【发布时间】:2015-07-30 05:07:09
【问题描述】:
我在我的 Meteor 应用程序中以编程方式创建了一个 Dropzone,而不是将文件发布到一个 url,我使用 CollectionFS / GridFS 将它们存储在我的 MongoDB 中,并通过迭代 getQueuedFiles 数组为每个文件调用 processFile(File),像这样:
dz.getQueuedFiles().forEach(function(element) {
Images.insert(element, function(err, fileObj){
if (err){
alert("Erreur!");
} else {
var imageId = fileObj._id;
arrayOfImageIds.push(imageId);
dz.processFile(element);
}
})
在文件大小变大之前一切顺利。然后,不知何故,进度条被卡住了一半,并且 processFile 永远不会完成(并且队列没有被清空)。即使我只是隔离 dz.processFile(element) 并注释掉写入文件的数据库,客户端也会挂起。
这是我的 Dropzone 设置:
Template.logoUpload.onRendered(function (){
Dropzone.autoDiscover = false;
dz = new Dropzone("form#dropzone", {
dictDefaultMessage : "DROP YOUR LOGO HERE",
autoProcessQueue: false,
addRemoveLinks: true,
dictRemoveFile: "Delete",
maxFiles: 2,
maxFilesize: 5,
maxThumbnailFilesize: 5,
accept: function(file, done){
done();
},
init: function() {
this.on("addedfile", function(file) {
Session.set("files", this.files.length);
if (this.getAcceptedFiles().length > 1) {
alert("max 2 files allowed");
this.removeFile(file);
}
}),
this.on("removedfile", function(file) {
Session.set("files", this.files.length);
}),
this.on("queuecomplete", function(file, response){
console.log("SUCCESFULLY UPLOADED");
console.log(arrayOfImageIds);
Session.set("imageIds", arrayOfImageIds);
})
}
});
});
有人知道如何解决这个问题吗?
【问题讨论】:
标签: mongodb meteor dropzone.js gridfs