【问题标题】:.NET Core Dropzone not receiving Internal Server Errors.NET Core Dropzone 未收到内部服务器错误
【发布时间】:2020-06-26 14:28:04
【问题描述】:

这是我的服务器端功能。我正在尝试将 InternalServerError 代码返回到 dropzone。但是,它总是说它是成功的。

我已经记录了所有返回的块,它的状态码也是成功的。

我是否错过了后端或前端的某些内容?

[ValidateAntiForgeryToken]
[HttpPost]
public async Task<HttpResponseMessage> SaveC(UploadDocumentViewModel Input)
{
    HttpResponseMessage response = new HttpResponseMessage { StatusCode = HttpStatusCode.Created };

    var Req = Request.Form;
    var b = Request.Form["RepositoryId"].ToString().Replace("{", "").Replace("}", "");
    if (Request.Form["RepositoryId"].ToString().Replace("{", "").Replace("}", "") == "")
    {
        response.StatusCode = HttpStatusCode.InternalServerError;
        response.Content = new StringContent("Chunk upload task is faulted or canceled!");
    }
    return response;

}

这是我的 javascript:

Dropzone.options.dropzone = {
    url:"@Url.Action("SaveC", "Document", new { area="Document"})",
    autoProcessQueue: false,
    addRemoveLinks: false,
    uploadMultiple: false,
    parallelUploads: 1,
    chunking: true,
    forceChunking: true,
    chunkSize: 100000,
    parallelChunkUploads: true,
    retryChunks: true,
    retryChunksLimit: 3,
    params: function (files, xhr, chunk) {
        if (chunk) {
            console.log(chunk);
            return {
                dzUuid: chunk.file.upload.uuid,
                dzChunkIndex: chunk.index,
                dzTotalFileSize: chunk.file.size,
                dzCurrentChunkSize: chunk.dataBlock.data.size,
                dzTotalChunkCount: chunk.file.upload.totalChunkCount,
                dzChunkByteOffset: chunk.index * this.options.chunkSize,
                dzChunkSize: this.options.chunkSize,
                dzFilename: chunk.file.name,
            };
        }
    },
    chunksUploaded: function (file, done) {
        //console.log(file);
        //console.log(done);
        $("#UploadActivity").val($("#UploadActivity").val() + file.name+ " " + file.status + "\r\n");
        this.autoProcessQueue = true;
        done();
    },
    init: function () {
        var submitButton = document.querySelector("#submit");
        var resetButton = document.querySelector("#reset");
        var token = $('input[name="__RequestVerificationToken"]').val();
        var wrapperThis = this;
        submitButton.addEventListener("click", function (e) {
            wrapperThis.processQueue();
            e.preventDefault();
            e.stopPropagation();
            e.stopImmediatePropagation();
            return false;
        });

        this.on('sending', function (data, xhr, formData) {
            formData.append("__RequestVerificationToken",token);
            formData.append("@Html.IdFor(x => x.CategoryId)", $("#@Html.IdFor(x => x.CategoryId)").val());
            formData.append("@Html.IdFor(x => x.RepositoryId)", $("#@Html.IdFor(x => x.RepositoryId)").val());
            formData.append("@Html.IdFor(x => x.BatchId)", $("#@Html.IdFor(x => x.BatchId)").val());
            formData.append("@Html.IdFor(x => x.BatchName)", $("#@Html.IdFor(x => x.BatchName)").val());
        });;

        this.on('error', function (file, message) {
            //toastr.error(message);
            console.log("Error");
            $("#UploadActivity").val($("#UploadActivity").val() + file.name + " " + file.status + "\r\n");
            wrapperThis.disable();
        });

        this.on('success', function (file, message) {
            console.log(file);
            console.log(message);
             $("#UploadActivity").val($("#UploadActivity").val() + file.name + " " + file.status + "\r\n");
            $(".dz-remove").hide();
            @*window.location.replace("@Url.Action("View","Batch",new { area="Batch"})?BatchId=@Model.BatchId");*@
        });

        this.on("queuecomplete", function () {
            //save to a counter
            //if all successful, move to next page
            console.log("ALL COMPLETED");
            this.options.autoProcessQueue = false;
        })
    }
};

【问题讨论】:

    标签: javascript jquery asp.net-core .net-core asp.net-core-mvc


    【解决方案1】:

    我设法通过从函数返回 ActionResult 并返回 BadRequest(); 来解决这个问题;

    【讨论】:

    • 你好@JianYA,你能分享分块上传的服务器端实现吗?我正在做但无法合并块。
    猜你喜欢
    • 2021-03-02
    • 2021-03-25
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多