如何使用JS SDK设置将对象上传到S3的存储类

How to set the storage class uploading an object to S3 with the JS SDK?

本文关键字:S3 存储 对象 JS 何使用 SDK 设置      更新时间:2023-09-26

我正在使用AWS JS SDK,使用托管上传器将对象从浏览器上传到S3。我想使用减少冗余的存储类,但我找不到设置它的方法。我试图在请求中设置x-amz-storage-class标头,如下所述https://github.com/aws/aws-sdk-js/issues/660但它似乎不适用于托管上传器。知道吗?

我使用的代码与这个相似

var bucket = new AWS.S3({params: {Bucket: 'myBucket'});
var params = {Key: file.name, ContentType: file.type, Body: file};
bucket.upload(params, function (err, data) {
  $('#results').html(err ? 'ERROR!' : 'UPLOADED.');
});

在此处找到https://blogs.aws.amazon.com/javascript/post/Tx3EQZP53BODXWF/Announcing-the-Amazon-S3-Managed-Uploader-in-the-AWS-SDK-for-JavaScript

StorageClass添加到参数中。

var params = {Key: file.name, ContentType: file.type, Body: file, StorageClass: 'REDUCED_REDUNDANCY'};

s3上传