I'm currently developping an image sharing plateform, using Meteor, CollectionFS and GridFS StorageAdapter.
I'm also using the excellent package dbarrett:dropzonejs, but problem is its implementation for CollectionFS, especially regarding XHR and uploadprogress stuff.
For now, i use this code.
Problem : when uploading files, i noticed in console unwanted POST requests alongside PUT requests from CollectionFS. I narrowed them down to xhr.send() in dbarrett_dropzone.js file. In attempt to stop them, i tried in template.rendered > dropzone options :
init: function() {
this.on("sending", function(file,xhr) {
xhr.abort(); //file.xhr.abort() does not work either...
});
} // console shows "NS_ERROR_NOT_INITIALIZED"
or overwriting dropzone.accept :
},
accept: function(file,done) {
done("dummy message");
},
but then it prevents Queue array to be populated, which is needed for CollectionFS inserts...
Question: i think needs to overwrite dropzone.uploadFiles(files) function, where all the xhr stuff is written, ... but all my attempts failed, can someone propose an implementation please ?
Ideally, i'm thinking such implementation would be like this :
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();
}
});