如何从 Fine-uploader 中的分块成功端点引发 onError

How to raise onError from chunking success endpoint in Fine-uploader

在我的应用程序中,当 chunking-success-endpoint returns JSON 类似于 {"error": "reason..."}(例如服务器无法将块重新组合在一起)时,onError 事件未被调用。

澄清一下,onError 事件 如果个别块失败。这是我遇到问题的最终成功请求。

我不确定我错过了什么。我应该以其他方式处理这个问题吗?

我的配置如下。提前致谢!

    var uploader = $('#fine-uploader').fineUploader({
        template: 'qq-template',
        debug: true,
        callbacks: {
            onAllComplete: function(succeeded, failed) {
                $('#doclib_tree').jstree(true).refresh()
                if (failed.length > 0) {
                    alert("Error: Some files were not uploaded");
                } else {
                    if (succeeded.length > 0 ) {
                        alert("Successfully uploaded " + succeeded.length + " file(s)");
                    }
                    this.reset();
                    toggle_upload();
                }
            },
            onError: function(id, name, errorReason, xhrOrXdr) {
                alert("Error uploading " + name + ".  Reason: " + errorReason)
            },
            onSubmit: function(id, name) {
                var promise = new qq.Promise();
                var dest = document.getElementById('dest_label').innerHTML.replace(/ > /g, "/")
                $.ajax({
                    'type': 'POST',
                    'async': false,
                    'url': "/documents/exists" ,
                    'data': {
                        'parents' : get_path(dest),
                        'name': name,
                    },
                    'success': function(data, textStatus, jqHXR) {
                        if ( check_session(data) ) {
                            promise.failure();
                        } else {
                            if (confirm("The file '" + dest + "/" + name + "' already exists.  Replace?"))
                                promise.success();
                            else
                                promise.failure();
                        }
                    },
                    'error': function(jqHXR, textStatus, errorThrown) {
                        promise.success();
                    }
                });
                return promise;
            },
        },
        chunking: {
            enabled: true,
            partSize: 20000000, // 20MB
            success: {
                endpoint: "documents/upload?success=1",
            }
        },
        resume: {
            enabled: true,
            recordsExpireIn: 1, // 1 day
        },
        request: {
            endpoint: "/documents/upload",
        },
        autoUpload: true
    });

来自分块成功部分下的文档:

For successful responses, you may return an empty body with a status of 200-204. Any other status code is determined to be a failure.

换句话说,要指示失败,您必须 return 一个 指示 失败的状态代码。根据错误的上下文选择最合适的状态代码。那时,Fine Uploader 应该确定文件以某种方式失败,并且您的 onError 处理程序将被您的服务器调用 error 属性 return。