0

我正在使用 FineUploader 上传几个文件,并且我有一个取消按钮来停止上传过程并删除所有已上传的文件。

服务器代码:

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'},
...
});

清除文件方法

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。我收到 imageUploader 的错误:“对象没有方法 'getUploads'”。

如果我修改 clearFiles 方法

function clearFiles() {
    if (myUploader && myUploader.getUploads()) {
        var array = myUploader.getUploads();
        for (var i = 0; i < array.length; i++) {
            myUploader.deleteFile(array[i].id);
        }
    }
    var array = document.getElementsByClassName("qq-upload-delete");
    for (var i = 0; i < array.length; i++) {
        array[i].style="display: inline;";
        array[i].click();
    }
}

有用。imageUploader 和 myUploader 的模板是相同的。

知道为什么我会出现“对象没有方法'getUploads'”错误吗?

4

0 回答 0