Google Storage + JQuery-File-Upload + Django + Signed URL,我应该如何更改submit()和相关选项?

我有以下js代码,它使用签名网址api获取签名网址,以便通过Django api将内容上传到Google存储。

当我将其与以下代码一起使用时:

xhr.open("PUT",data.signed_url); 
xhr.setRequestHeader('Content-Type',file.type); 
xhr.send(file);

工作正常,我可以将非常大的文件上传到Google存储空间。但是显然,当我这样做时,我无法使用jquery-file-upload的任何进度条功能。

您能否建议我如何更改data.submit(),应将其放置在哪里,以及在提交之前应如何更改选项或设置。我应该覆盖添加或提交回调吗?

我觉得缺少对带有Jquery-file-upload的Google存储的支持,因为唯一的示例仅包含以下链接中的绝对Google Blobstore:https://github.com/blueimp/jQuery-File-Upload/wiki/Google-App-Engine

$("#fileupload").fileupload({
dataType: 'json',type: 'PUT',sequentialUploads: true,submit: function(e,data) {
    var $this = $(this);
    $.each(data.files,function(index,file) {
        // pack our data to get signature url
        var formData = new FormData();
        formData.append('filename',file.name);
        formData.append('type',file.type);
        formData.append('size',file.size);

        // Step 3: get our signature URL
        $.ajax({
            url:  '/api/getsignedurl/',type: 'POST',processData: false,contentType: false,dataType: 'json',headers: {
                'X-CSRFToken': Cookies.get('csrftoken'),},primary_data: data,data: formData
        }).done(function (data) {
            // Step 5: got our url,push to GCS
            const xhr = new XMLHttpRequest();
            if ('withCredentials' in xhr) {
                console.log("With credentials");
                xhr.open("PUT",data.signed_url,true);
            }
            else if (typeof XDomainRequest !== 'undefined') {
                console.log("With domainrequest");
                xhr = new XDomainRequest();
                xhr.open("PUT",data.signed_url);
            }
            else {
                console.log("With null");
                xhr = null;
            }

            //What shall I do to make the following work for uploading GS
            this.primary_data.url = data.signed_url;
            this.primary_data.headers={'Content-Type': file.type};
            this.primary_data.submit();

            xhr.onload = () => {
                const status = xhr.status;
                if (status === 200) {

                } else {
                    alert("Failed to upload 1: " + status);
                }
            };

            xhr.onerror = () => {
                alert("Failed to upload 2");
            };
            //When the code below uncommented,it uploads to GS succesfully.
            //xhr.setRequestHeader('Content-Type',file.type);
            //xhr.send(file);
        });
    });
},

这也是我为GS Bucket设置的cors。

 [
  {
    "origin": ["*"],"responseHeader": ["Content-Type","access-control-allow-origin"],"method": ["GET","PUT","OPTIONS"],"maxAgeSeconds": 60
  }
]
dunhuangheisha 回答:Google Storage + JQuery-File-Upload + Django + Signed URL,我应该如何更改submit()和相关选项?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2516335.html

大家都在问