簡體   English   中英

WebKitFormBoundary 包含在直接上傳到 s3 的文件有效負載中

[英]WebKitFormBoundary included in file payload on direct upload to s3

我有一個 dropzone.js 實例,它使用 CORS 將文件直接上傳到 S3 存儲桶,然后將 javascript 中的文件信息傳遞給我使用。 這是我遵循的教程......

文件上傳本身似乎工作正常,文件顯示在正確文件路徑的 s3 存儲桶中,但是所有文件都包含類似這樣的內容

------WebKitFormBoundaryMH4lrj8VmFKgt1Ar
Content-Disposition: form-data; name="files[0]"; filename="image-name.png"
Content-Type: image/png


IMAGE CONTENT HERE

------WebKitFormBoundaryMH4lrj8VmFKgt1Ar--

我一生都無法弄清楚為什么會發生這種情況。 我上傳的文件類型/mime 無關緊要,一切都包括它。

任何幫助將不勝感激!

在你的 init 中:function() { .. }

添加以下內容:

 self.on("sending", function(file, xhr, formData) { var _send = xhr.send; xhr.send = function() { _send.call(xhr, file); } });

@TadasTamosauskas 是正確的,捕獲“發送”事件以修補 xhr 不適用於分塊上傳。

下面是另一種方法,它使用作為選項傳入 Dropzone 的 params 函數修補 xhr。 分塊執行路徑還添加了使用 OneDrive API 上傳可恢復文件所需的標頭,如下所述: https ://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession?view = odsp-graph-online

 const CHUNK_SIZE=10485760 //10MiB Dropzone.options.dropzone = { method: "put", headers: { 'Cache-Control': null, 'X-Requested-With': null }, filesizeBase: 1024, maxFilesize: 102400, // 100G in MB, max onedrive filesize chunking: true, chunkSize: CHUNK_SIZE, params: function(files, xhr, chunk) { if (chunk) { const chunk_start = (chunk.index * CHUNK_SIZE) xhr.setRequestHeader('Content-Range', 'bytes ' + chunk_start + '-' + (chunk_start + chunk.dataBlock.data.size - 1) + '/' + files[0].size) var _send = xhr.send xhr.send = function() { _send.call(xhr, chunk.dataBlock.data) } } else { var _send = xhr.send xhr.send = function() { _send.call(xhr, files[0]) } } } }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM