[英]How to Implement Multipart Upload via CloudFront?
This is currently my code that successfully uploading file to S3 via CloudFront: 当前 , 这是我的代码 ,已通过CloudFront成功将文件上传到S3:
let fileObject = thisUploader.getFile(id); //returns File API let reader = new FileReader(); //using the FileReader API to read files reader.onload = function () { $.ajax({ url: 'http://sampleId.cloudfront.net/video.mp4?Policy=examplePolicy&Signature=exampleSignature&Key-Pair-Id=exampleKey', type: 'PUT', contentType: fileObject.type, data: reader.result, processData: false, crossDomain: true }); } reader.readAsArrayBuffer(fileObject);
Now for the chunking upload (or multipart in AWS terms), I have no idea how to do it via CloudFront (there's only document for S3). 现在,对于分块上传(或AWS术语中的多部分),我不知道如何通过CloudFront(只有S3的文档)来实现。
So my question is what are all of the steps needed to implement multipart upload via CloudFront? 所以我的问题是通过CloudFront实施分段上传需要采取什么所有步骤?
What I have tried: I have enabled the Forward Query Strings
option in the CloudFront console, and add the param uploads
to whitelist. 我尝试过的操作:我在CloudFront控制台中启用了
Forward Query Strings
选项,并将参数uploads
添加到白名单。 I tried the guides for S3, and just test this code for initiating the mutlipart upload (notice the added uploads
param): 我尝试了S3的指南 ,仅测试了以下代码以启动mutlipart上载(请注意添加的
uploads
参数):
$.ajax({ url: 'http://sampleId.cloudfront.net/video.mp4'+'?uploads'+'&Policy=examplePolicy&Signature=exampleSignature&Key-Pair-Id=exampleKey', type: 'POST', contentType: 'application/json' });
It sent a preflight request (OPTIONS) and returns 200 OK
with these response headers: 它发送了预检请求(OPTIONS),并使用以下响应标头返回
200 OK
:
Access-Control-Allow-Headers: content-type
Access-Control-Allow-Methods: GET, PUT, HEAD, POST
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3000
Connection: keep-alive
Content-Length: 0
Date: Thu, 02 Aug 2018 07:03:01 GMT
Server: AmazonS3
Vary: Origin, Access-Control-Request-Headers, Access-Control-Request-Method
Via: 1.1 7111a943ba8327e4a6723f271fc9f7c4.cloudfront.net (CloudFront)
X-Amz-Cf-Id: oeE4D7FM8TyxE7NtmVidbyADGLqvwOnc49XdI1ps-tHIUKXrdm2PGg==
X-Cache: Miss from cloudfront
But the real POST request returns 403 Forbidden
with these response headers: 但是实际的POST请求返回
403 Forbidden
以及以下响应标头:
Accept-Ranges: none
Access-Control-Allow-Methods: GET, PUT, HEAD, POST
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3000
Age: 13976
Connection: keep-alive
Content-Length: 445
Content-Type: text/html
Date: Thu, 02 Aug 2018 03:10:05 GMT
ETag: "07468170dde4c34c5990eee2d1c2ae1e"
Last-Modified: Wed, 01 Aug 2018 08:34:47 GMT
Server: AmazonS3
Via: 1.1 7111a943ba8327e4a6723f271fc9f7c4.cloudfront.net (CloudFront)
X-Amz-Cf-Id: EWPPWw0l9BTmhFFe39HWdUuCp2Ab2L3yE5bj9wEqFvl3mVbNmt28Pg==
x-amz-replication-status: FAILED
x-amz-version-id: yLhhgPevn2eeofp7kEmcvixP3iW.vj7S
X-Cache: Error from cloudfront
不幸的是,Cloudfront不能上传,您需要通过S3路径或前缀URL上传文件。
In the end, I've to turn off the Restrict Viewer Access option of the Cloudfront. 最后,我必须关闭Cloudfront的Restrict Viewer Access选项。 It seems to not play well with Multipart Upload, or the query string param forward is not working properly when it is turn on.
分段上传似乎不能很好地发挥作用,或者打开它时查询字符串参数转发无法正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.