AWS S3 node.js SDK uploaded file and folder permissions

后端 未结 3 1261
有刺的猬
有刺的猬 2021-01-31 13:48

I\'m uploading file to S3 using aws-sdk package:

fs.readFile(sourceFile, function (err, data) {
    if (err) { throw err; }

    s3.client.putObject({
        Bu         


        
3条回答
  •  春和景丽
    2021-01-31 14:20

    The following works like a charm. (Note the ACL key in params)

    const params = {
      Bucket: bucketName + path,
      Key: key,
      Body: buffer,
      ContentEncoding: 'base64',
      ContentType: 'image/jpeg',
      ACL:'public-read'
    };
    await s3.putObject(params).promise();

    Note: IAM permission "s3:PutObjectACL" must be included in the appropriate policy otherwise you will get Access Denied errors.

提交回复
热议问题