To upload a file to the server, I use the following code snippet:
var fd = new FormData();
fd.append('folder', 'html');
fd.append('permission', 0);
fd.append("file", file, file.name);
After selecting the file from an input field, my request is as follows:
$.ajax({
type: "POST",
url: getURI("fileupload"),
success: function (data) {
reader.onload = function (e) {
callback(data.body.url, {
alt: ''
});
};
reader.readAsDataURL(file);
},
error: function (error) {
// handle error
},
async: true,
data: fd,
cache: false,
contentType: false,
processData: false,
timeout: 60000
});
1) Uploading the initial file works fine. 2) When trying to upload a second file, it does upload successfully, but there seems to be an issue with the FormData - when attempting to send multiple files, only the last one gets sent while the others are still being attempted.
Is there a way to remove previous FormData entries?