我正在使用 FineUploader 上传几个文件,并且我有一个取消按钮来停止上传过程并删除所有已上传的文件。当我在每个文件中单击“删除”时,它工作正常,但从前一段时间(不确定是更新到 3.9 还是之前)我收到一个空白警报和“删除失败”消息,但是文件已从服务器中删除,因此 Servlet 工作正常。
我删除文件的代码是这样的:
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();
}
}
我猜问题是否可能是在不等待确认消息的情况下尝试删除文件(所以我在得到前一个响应之前删除下一个)或其他什么,但我无法解释空白警报。我没有找到任何有关此的文档或示例。有任何想法吗?
控制台日志:
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]
服务器代码:
public void doDelete(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
String uuid = req.getPathInfo().replaceAll("/", "");
FileUtils.deleteUploadedFile(uuid);
resp.setStatus(successResponseCode);
}
FineUploader 定义
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'},
...
});
新的 clearFiles 方法
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);
}
}
}
这不适用于 imageUploader,但它适用于 myUploader。知道为什么吗?