Categories
JavaScript Answers

How to set uploaded file and folder permissions with AWS S3 Node.js SDK?

Spread the love

Sometimes, we want to set uploaded file and folder permissions with AWS S3 Node.js SDK.

In this article, we’ll look at how to set uploaded file and folder permissions with AWS S3 Node.js SDK.

How to set uploaded file and folder permissions with AWS S3 Node.js SDK?

To set uploaded file and folder permissions with AWS S3 Node.js SDK, we can set the ACL property of the object that we call putObject with.

For instance, we write

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

to call putObject with params that has ACL set to 'public-read' to let anyone read the uploaded file.

Conclusion

To set uploaded file and folder permissions with AWS S3 Node.js SDK, we can set the ACL property of the object that we call putObject with.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *