使用FineUploader删除文件时出错

时间:2013-09-24 14:41:36

标签: javascript file-io fine-uploader

我使用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。知道为什么吗?

1 个答案:

答案 0 :(得分:0)

onDeleteComplete中存在影响功能的问题。解决这个问题,原来的clearFiles有效。

非常感谢FineUploader团队的帮助!!