我目前正在开发一个图像共享平台,使用Meteor,CollectionFS和GridFS StorageAdapter。如何覆盖DropzoneJS的GridH的XHR?
我也使用优秀的包dbarrett:dropzonejs,但问题是它的CollectionFS的实现,特别是关于XHR和uploadprogress的东西。
现在,我用this code。
问题:当上传文件时,我注意到控制台不需要的POST请求 以及来自CollectionFS的PUT请求。 我将它们缩小到dhrrett_dropzone.js文件中的xhr.send()。 在企图阻止他们,我试图在template.rendered>悬浮窗选项:
init: function() {
this.on("sending", function(file,xhr) {
xhr.abort(); //file.xhr.abort() does not work either...
});
} // console shows "NS_ERROR_NOT_INITIALIZED"
或覆盖dropzone.accept:
},
accept: function(file,done) {
done("dummy message");
},
但随后它防止队列阵列要填充,这是需要对于CollectionFS插入...
问题:我觉得需要覆盖dropzone.uploadFiles(文件)功能,所有的东西XHR写入, ......但所有我的尝试失败了,有人可以提出一个实施吗?
理想的情况下,我在想这样的实现方式是这样的:
Template.albumContent.rendered = function() {
var dz = new Dropzone("form#dzId", {
url: "#",
autoProcessQueue: false,
addRemoveLinks: true,
acceptedFiles: "image/*",
init: function() {
this.on("success", function(file) {
Meteor.setTimeout(function() {
dz.removeFile(file);
},3000)
});
},
uploadFiles: function(files) {
var dzgqf = dz.getQueuedFiles();
if (dzgqf.length) {
dzgqf.forEach(function(file) {
var fsFile = new FS.File(file);
fsFile.owner = Meteor.userId();
Images.insert(fsFile, function(error, fileObj) {
if (error) throw new Meteor.Error("Error uploading this file : ", fsFile);
// how to pass properly fileObj.updateProgress() stuff to dz.uploadprogress event ???
});
});
}
}
});
}
Template.albumContent.events({
"click .js-upload-all-images": function(event, template) {
event.preventDefault(); event.stopPropagation();
var dz = Dropzone.getElement("#dzId").dropzone;
console.log("Queued files : ", dz.getQueuedFiles());
dz.processQueue();
}
});