[英]How to make an AWS S3 file public accessible using AW S3 SDK's createPresignedPost method?
I have a use case to keep the AWS S3 Bucket Private as default but,我有一个用例将 AWS S3 Bucket Private 保留为默认值,但是,
Make certain objects Public while uploading to AWS S3.在上传到 AWS S3 时将某些对象设为公开。
I am using the following code to sign the AWS S3 url using and ACL setting as public-read
-我正在使用以下代码来签署 AWS S3 url 使用和 ACL 设置为
public-read
-
module.exports.generateS3PostSignedUrl = async (bucketName, bucketKey, objectExpiry) => {
let s3Client = new AWS.S3({
region: 'some-region'
});
let signingParams = {
Expires: objectExpiry,
Bucket: bucketName,
Fields: {
key: bucketKey,
},
Conditions: [
['acl', 'public-read']
],
ACL: 'public-read'
}
let s3createPresignedPost = util.promisify(s3Client.createPresignedPost).bind(s3Client);
let signedUrl = await s3createPresignedPost(signingParams);
return signedUrl;
};
Request while uploading -上传时请求 -
I am able to upload the file to AWS S3, if I remove the conditions array in signing params,我可以将文件上传到 AWS S3,如果我删除了签名参数中的条件数组,
but the file is still not public when I click its url.但是当我单击其 url 时,该文件仍未公开。
I believe I have done something wrong code on signingParams
part.我相信我在
signingParams
部分做了一些错误的代码。
Ref -参考 -
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#createPresignedPost-property https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#createPresignedPost-property
The order of parameters matters here.参数的顺序在这里很重要。 Put acl parameter before the file and it should work;
将 acl 参数放在文件之前,它应该可以工作; otherwise S3 just ignores the value you provided.
否则 S3 只会忽略您提供的值。
Below are the example screenshots with different placement of parameters in form-data.以下是在表单数据中参数位置不同的示例屏幕截图。
Also, be sure to give execute the createPresignedPost by a user with s3:PutObjectAcl
and s3:PutObject
permissions.此外,请确保由具有
s3:PutObjectAcl
和s3:PutObject
权限的用户执行 createPresignedPost。
The correct order of form-data parameters表单数据参数的正确顺序
The same request but with acl
parameter being placed after file
(Ignored by S3)相同的请求,但
acl
参数放在file
之后(被 S3 忽略)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.