Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3 node.js SDK uploaded file and folder permissions

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

fs.readFile(sourceFile, function (err, data) {     if (err) { throw err; }      s3.client.putObject({         Bucket: bucketName,         Key: 'Folder/image.jpg',         Body: data     }, function (res) {             console.log('Successfully uploaded file.');         })  }); 

I I need to make uploaded file to be downloadable via cloudfront, if I asume right, I need to set permissions on file: Everyone Open/Download, Folder2 should be made public (via menu Make Public). So 2 questions:

1) How to set\modify permissions on uploaded file\folder?

2) How make Folder public using AWS SDK for node.js.

like image 775
WHITECOLOR Avatar asked Jan 17 '13 09:01

WHITECOLOR


People also ask

How do I access an S3 bucket from AWS SDK?

To access Amazon Simple Storage Service, create an AWS. S3 service object. Call the listBuckets method of the Amazon S3 service object to retrieve a list of your buckets. The data parameter of the callback function has a Buckets property containing an array of maps to represent the buckets.

How do I upload files and folders to an S3 bucket?

To upload folders and files to an S3 bucketSign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to upload your folders or files to. Choose Upload.

Does S3 preserve file permissions?

Thanks! S3 isn't a Linux file system. It won't retain any Linux permissions because they don't apply to S3.


1 Answers

Found it http://docs.aws.amazon.com/AmazonS3/latest/dev/ACLOverview.html#CannedACL

need to add option in putObject or upload:

ACL:'public-read' 
like image 150
WHITECOLOR Avatar answered Oct 13 '22 18:10

WHITECOLOR