如何在fine uploader中在运行时添加标头

How to add headers at runtime in fine uploader

本文关键字:添加 运行时 uploader fine      更新时间:2023-09-26

我正在使用fine uploader在服务器上上传文件,为此我需要进行2次web api调用。

点击按钮,第一个web api保存值并以整数形式返回结果,我需要在上传时将该整数结果传递到每个文件的头中。但是我不能在头中传递值,

代码,

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());
            }
        }
    });

我正在调用第一个请求的成功块中的上传功能,

$.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");
            }
        });

在这里,我想在onUpload事件中传递RequestId标头,但它不起作用,我需要做什么更改才能实现。

request选项有一个customHeaders属性,允许您设置任何自定义标头。

您的构造函数调用应该类似

artistmanualuploader = new qq.FineUploader({
    ...
    request: {
        endpoint: "FoaUrl.AddEvaluationFiles",
        customHeaders: {
            "EvaluationRequestId": $("#CurrentEvaluationReqId").val()
        }
    },
    ...
});