How to make an AWS S3 file public accessible using AW S3 SDK's createPresignedPost method?

杀马特。学长 韩版系。学妹 提交于 2020-01-14 06:17:07

问题


I have a use case to keep the AWS S3 Bucket Private as default but,
Make certain objects Public while uploading to AWS S3.

I am using the following code to sign the AWS S3 url using and ACL setting as 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,
but the file is still not public when I click its url.
I believe I have done something wrong code on signingParams part.


Ref -
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#createPresignedPost-property

Upload file to s3 with POST

来源:https://stackoverflow.com/questions/59484157/how-to-make-an-aws-s3-file-public-accessible-using-aw-s3-sdks-createpresignedpo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!