简体   繁体   English

WebKitFormBoundary 包含在直接上传到 s3 的文件有效负载中

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

I have a dropzone.js instance that uploads files directly to an S3 bucket using CORS and then passes me the file information inside of javascript to use.我有一个 dropzone.js 实例,它使用 CORS 将文件直接上传到 S3 存储桶,然后将 javascript 中的文件信息传递给我使用。 This is the tutorial I followed for it...这是我遵循的教程......

The file upload itself seems to work fine, the files show up in the s3 bucket at the correct file path, however all of the files include something like this wrapped around it文件上传本身似乎工作正常,文件显示在正确文件路径的 s3 存储桶中,但是所有文件都包含类似这样的内容

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


IMAGE CONTENT HERE

------WebKitFormBoundaryMH4lrj8VmFKgt1Ar--

I cannot for the life of me figure out why this is happening.我一生都无法弄清楚为什么会发生这种情况。 It doesn't matter what type/mime of file I upload, everything includes it.我上传的文件类型/mime 无关紧要,一切都包括它。

Any help would be greatly appreciated!任何帮助将不胜感激!

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

add the following:添加以下内容:

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

@TadasTamosauskas is correct that catching the 'sending' event to patch xhr will not work for chunked uploads. @TadasTamosauskas 是正确的,捕获“发送”事件以修补 xhr 不适用于分块上传。

Below is another method that patches xhr with a params function passed in as an option to Dropzone.下面是另一种方法,它使用作为选项传入 Dropzone 的 params 函数修补 xhr。 The chunked execution path also adds the headers required for a resumable file upload using the OneDrive API as documented here: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession?view=odsp-graph-online分块执行路径还添加了使用 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