I am uploading several files with FineUploader and I have a cancel button to stop the upload process and delete all the files that have been uploaded. When I click on "Delete" in each file it works fine, but since some time ago (not sure if it was with the update to 3.9 or before that) I am getting a blank alert and a "Delete Failed" message, but the files are deleted from the server so the Servlet is working fine.
My code to delete the files is something like this:
function clearFiles() {
var array = document.getElementsByClassName("qq-upload-delete");
for (var i = 0; i < array.length; i++) {
array[i].style="display: inline;";
array[i].click();
}
}
I am guessing if the problem could be being trying to delete the files without waiting to the confirmation message (so I am deleting the next one before I get the response from the previous one) or something else, but I can't explain the blank alert. I didn't find any documentation or example about this. Any ideas?
Console Log:
Uncaught ReferenceError: Modernizr is not defined.
Uncaught Error: Element not found drop.
[FineUploader 3.9.0-3] DELETE request for 0 has failed - response code 0
[FineUploader 3.9.0-3] Delete request for 'test File.pdf' has failed. id: test File.pdf, fileName: Delete request failed with response code 0, reason: [Object XMLHttpRequest]
Server code:
public void doDelete(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
String uuid = req.getPathInfo().replaceAll("/", "");
FileUtils.deleteUploadedFile(uuid);
resp.setStatus(successResponseCode);
}
FineUploader definition
myUploader = new qq.FineUploader({
element: $('#file-uploader')[0],
multiple: false,
autoUpload: true,
deleteFile: {enabled: true, forceConfirm: false, endpoint: '/upload-portlet/fineupload/receiver'},
...
});
imageUploader = new qq.FineUploader({
element: $('#image-uploader')[0],
multiple: false,
autoUpload: true,
deleteFile: {enabled: true, forceConfirm: false, endpoint: '/upload-portlet/fineupload/receiver'},
...
});
New clearFiles method
function clearFiles() {
if (myUploader && myUploader.getUploads()) {
var array = myUploader.getUploads();
for (var i = 0; i < array.length; i++) {
myUploader.deleteFile(array[i].id);
}
}
if (imageUploader && imageUploader.getUploads()) {
var array = imageUploader.getUploads();
for (var i = 0; i < array.length; i++) {
imageUploader .deleteFile(array[i].id);
}
}
}
This doesn't works for imageUploader but it does for myUploader. Any idea why?
There was a problem in onDeleteComplete that affected the functionality. Fixing that, the original clearFiles worked.
Thank you very much to the FineUploader team for the help!!