I have a form that allows you to upload files to various fields that are dynamically added to the form. I am using the Blueimp jQuery file upload plugin. I am trying to send multiple files on a single request. I do not want to send multiple requests. When I submit the form, the files that will be uploaded will not be included in the request. I support them in the filesList array in the add method and don't forget to override existing values. Then I use the send parameter to send the files. Although, they are not included in the ajax post. What am I missing? I have seen other users try to do this. However, I did not find a convincing working example. Below is my code:
var fileList = [],
exists = false;
$form.fileupload({
autoUpload: false,
singleFileUpload: false,
url: '/handler.php',
add: function(e, data) {
exists = false;
for(var i = 0, len = filesList.length; i < len; i++) {
if(filesList[i].paramName === data.paramName) {
exists = true;
filesList[i] = data;
break;
}
}
if(!exists) {
filesList.push(data);
}
$form.off('submit').one('submit', function(e) {
$form.fileupload('send', {
files: filesList
});
return false;
});
}
})