繁体   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