简体   繁体   English

如何通过CloudFront实施分段上传?

[英]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.

相关问题 使用AWS-SDK-JS通过CloudFront分发进行S3分段上传 - S3 Multipart upload via cloudfront distribution with aws-sdk-js 如何使用nodejs实现分段文件上传代理? - How to implement multipart file upload proxy using nodejs? Javascript将图像作为URI数据,如何通过multipart / form-data表单上传此图像? - Javascript has an image as URI data, how do I upload this image via a multipart/form-data form? 是否可以通过Java脚本上传到Cloudfront,最好使用Gears进行上传 - Is it possible to upload to Cloudfront via Javascript preferably using Gears for uploading 通过 fetch 从 Uint8ClampedArray 创建多部分文件上传 - Create multipart file upload from Uint8ClampedArray via fetch Angularjs如何上传多部分表单数据和文件? - Angularjs how to upload multipart form data and a file? 如何使用multipart上传文件使用XMLHttpRequest? - how to use multipart to upload file using XMLHttpRequest? 如何在AngularJS中上传多部分表单? - How do I upload a multipart form in AngularJS? 如何通过JavaScript将图像添加到多部分 - How to add image to multipart via javascript 如何使用codeigniter实现上传脚本 - how to implement an upload script with codeigniter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM