POST All queued files as one job
SamuelDev opened this issue · 2 comments
I am trying to have my implementation of the plugin send all queued files to my controller action at one time. Is there an option to do this natively with this plugin?
I tried setting the queue to false, but this sends all the files in parallel, rather than as one post action.
Needed the exact same thing. As it doesn't seem to support this feature I ended up hacking the source a bit:
In DmUploader.prototype.startAll
// or upload them all
for (var i = 0; i < this.queue.length; i++) {
this.queue[i].upload(this.queue);
break;
}
and in start of DmUploaderFile.prototype.upload
DmUploaderFile.prototype.upload = function(files)
{
var files = files || [this];
var file = this;
/*
if (!file.canUpload()) {
if (file.widget.queueRunning && file.status !== FileStatus.UPLOADING) {
file.widget.processQueue();
}
return false;
}*/
// Form Data
var fd = new FormData();
for (var e = 0; e < files.length; e++) {
if (files[e].canUpload()) {
fd.append(files[e].widget.settings.fieldName, files[e].data);
}
}
...
using a array type fieldName as fieldName: 'attachment_files[]',
and this for the rest of my form:
extraData: function() {
var paramObj = {};
$.each($('#drop-area').closest('form').serializeArray(), function(_, kv) {
paramObj[kv.name] = kv.value;
});
return paramObj;
}
now it almost works as a normal form, just need to intercept the submit event and call dmUploader('start')
Unfortunately I don't work for the company that I needed to do this for anymore, so I can't post exactly what I did.
Essentially how I solved it was to generate a job id guid with the control, send that back with each file, and send back the queue position of each file. I would store each file locally on the server in a folder with the job guid and once file with position 0 was done uploading, do what I needed to with all the files. Once that was done I would delete the folder with the matching guid.