How to add headers at runtime in fine uploader

2019-08-08 17:42发布

I am using fine uploader for uploading file on server, For this I need to make 2 web api calls.

On button click, First web api saving value and returning result in integer, and I need to pass that integer result in header for each file while uploading. But I am not able to pass values in headers,

code,

uploader = new qq.FineUploader({
        element: $('#manual-fine-uploader1')[0],
        request: {
            endpoint: Url.AddEvaluationFiles,
        },
        autoUpload: false,
        text: {
            uploadButton: '<i class="icon-plus icon-white"></i> Select Files'
        },
        debug: true,
        callbacks: {
            onSubmit: function (id, fileName) {

            },
            onStatusChange: function (id, oldStatus, newStatus) {
                if (newStatus == "uploading") {
                    alert("Add header");
                }
            },
            onUpload: function (id, name) {
                alert("Onupload");
                this.append("RequestId", $("#ReqId").val());
            }
        }
    });

I am calling upload function in success block of first request,

$.ajax({
            type: "POST",
            url: Url.Details,
            data: fileData,
            async: false,
            success: function (result) {
                if (result == 0) {
                    toastr.error("Please pass user id");
                } else {
                    $("#ReqId").val(result);
                    alert($("#ReqId").val());

                    uploader.uploadStoredFiles();

                }
            },
            error: function (err) {
                toastr.error("Not able to upload art details");
            }
        });

Here I want to pass RequestId header in onUpload event, but it's not working, What changes I need to make to make it happen.

1条回答
手持菜刀,她持情操
2楼-- · 2019-08-08 18:20

The request option has a customHeaders property, that allows you to set any custom header.

Your constructor call should look something like

artistmanualuploader = new qq.FineUploader({
    ...
    request: {
        endpoint: "FoaUrl.AddEvaluationFiles",
        customHeaders: {
            "EvaluationRequestId": $("#CurrentEvaluationReqId").val()
        }
    },
    ...
});
查看更多
登录 后发表回答