简体   繁体   English

使用AWS-SDK-JS通过CloudFront分发进行S3分段上传

[英]S3 Multipart upload via cloudfront distribution with aws-sdk-js

I'm trying to make an multipart upload using cloudfront as an endpoint, I know this is possible ( https://github.com/aws/aws-sdk-js/issues/423 ), and I've also opened a ticket on the Github of aws-sdk-js, I don't know if I'm missing some configuration option, or something else, but I'm not able to do an upload trough Cloufront using the aws sdk multipart upload functions, I always get 503's on the PUT requests. 我正在尝试使用Cloudfront作为端点进行分段上传,我知道这是可能的( https://github.com/aws/aws-sdk-js/issues/423 ),并且我还开了票在aws-sdk-js的Github上,我不知道是否缺少某些配置选项或其他东西,但是我无法使用aws sdk分段上传功能来通过Cloufront进行上传,我总是在PUT请求上获得503。

<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<AWSAccessKeyId>...</AWSAccessKeyId>
<StringToSign>POST

application/octet-stream; charset=UTF-8

x-amz-acl:private
x-amz-date:Tue, 28 Jul 2015 15:22:01 GMT
x-amz-user-agent:aws-sdk-js/2.1.40
/bucket-name/test_797965294</StringToSign>
<SignatureProvided>...</SignatureProvided>
<StringToSignBytes>....</StringToSignBytes><RequestId>7488F0A2F70E4AC5</RequestId>
<HostId>...</HostId>
</Error>

I'm using the following code start the multi-part upload: 我正在使用以下代码开始分段上传:

AWS.config.update({
    accessKeyId: 'XXXXXXXXXXXXXXXXX',
    secretAccessKey: 'XXXXXXXXXXXXXXXXXX'
});

var s3Client = new AWS.S3({
    endpoint: 'XXXXXXXX.cloudfront.net',
    s3BucketEndpoint: true,
    region: 'eu-west-1'
});

var TEMP_filename = 'test_' + Math.floor(1000000000*Math.random());

var params = {
    Bucket: 'bucket-name',
    Key: TEMP_filename, 
    ACL: 'private'
};

s3Client.createMultipartUpload(params, function(err, data) {
    if (err) {
        console.log(err, err.stack); // an error occurred
    } else {
        console.log(data);           // successful response
    }
});

And the result is: 结果是: Google控制台的网络输出

索取详细资料

Am I missing something in the configuration of the client? 我在客户端的配置中缺少什么吗?

It's also worth to mention, that when using, AWS.S3.ManagedUpload, almost everything works perfectly. 还值得一提的是,在使用AWS.S3.ManagedUpload时,几乎所有功能都能完美运行。 If the file size is smaller than the required to make an multipart upload, everything goes ok, but when switching to an multipart upload everything breaks again. 如果文件大小小于进行分段上传所需的文件大小,则一切正常,但切换到分段上传时,一切都会再次中断。 It's always on the POST requests, the PUT requests seem to work fine. 它总是在POST请求上,PUT请求似乎可以正常工作。

The only way this seems to work, is using the putObject , function using this I don't have any problem whatsoever, but I need resume support, and that can only be achieved trough the multipart upload. 这似乎可行的唯一方法是使用putObject ,使用此函数我没有任何问题,但是我需要恢复支持,并且只能通过分段上传来实现。

BTW, I'm using the latest version of the SDK: aws-sdk-js/2.1.40 顺便说一句,我正在使用最新版本的SDK:aws-sdk-js / 2.1.40

Someone responded to the ticket I opened on github ( https://github.com/aws/aws-sdk-js/issues/669 ), the problem as a bad configuration on cloudfront. 有人回应了我在github( https://github.com/aws/aws-sdk-js/issues/669 )上打开的故障单,该问题是在Cloudfront上的错误配置。

To enable multipart uploads, we need to configure the forward query strings on the Cloudfront Web destribution. 要启用分段上传,我们需要在Cloudfront Web分发上配置正向查询字符串。

After enabling this, and waiting for the deployment of the cloudfront distribution, everything worked perfectly. 启用此功能后,等待部署Cloudfront分发,一切都将正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 AWS-SDK-JS 使用普通 Javascript 将大文件作为流上传到 s3 - Upload large files as a stream to s3 with Plain Javascript using AWS-SDK-JS AWS开发工具包JS:分段上传到S3导致数据损坏 - AWS SDK JS: Multipart upload to S3 resulting in Corrupt data 使用angular + aws-sdk-js +预签名网址将文件上传到S3 - Uploading a file to S3 with angular + aws-sdk-js + pre-signed url 通过AWS SDK创建签名的S3和Cloudfront URL - Creating signed S3 and Cloudfront URLs via the AWS SDK 如何在浏览器中使用 javascript sdk 在 aws s3 存储桶中上传多部分文件 - How to upload multipart files in aws s3 bucket using javascript sdk in browser 尝试通过 JS SDK 将对象上传到 S3 时 AuthorizationHeaderMalformed - AuthorizationHeaderMalformed when trying to upload object to S3 via JS SDK 来自浏览器JS SDK的AWS S3 multipart / uploadPart静默失败 - AWS S3 multipart / uploadPart silent fail from browser JS SDK 将aws-sdk-js与CognitoSync服务一起使用时出现InvalidSignatureException - InvalidSignatureException while using aws-sdk-js with CognitoSync service 如何使用 aws-sdk-js 列出日期范围内的对象? - How to list objects in a date range with aws-sdk-js? 如何通过CloudFront实施分段上传? - How to Implement Multipart Upload via CloudFront?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM