Vishnu
Vishnu

Reputation: 755

How to provide public read access to a all files in folder by s3fs in node.js?

How to provide public read access to a all files in folder by s3fs in node.js?

I am trying to rename the folder name by using following code:

  fsImpl.mkdirp(main_folder_path).then(function () {
                        fsImpl.copyDir(copy_folder_path+'/', main_folder_path+'/').then(function () {
                                console.log("copy directory")
                            }, function (reason) {
                                res.json('error');
                            });
                        });

Successfully all files are get copying to new folder,But the copies files don't have public access..I have searched some sources and finally i get following answer

fsImpl.writeFile(fileName, stream,{ACL: 'public-read'}).then(function (err,data) {  
     // code
 })

But I need to give access to the folder . How do i do that??

Thanks in Advance.

Upvotes: 1

Views: 1417

Answers (1)

Priyank lohan
Priyank lohan

Reputation: 483

Did your S3 bucket have public read access?? if not go to your S3 account and there you find Permissions Tab after click on that you will have three new Tabs. from those tabs Click on Bucket Policy. and Add the following JSON code there.

{
"Version": "2008-10-17",
"Statement": [
    {
        "Sid": "AllowPublicRead",
        "Effect": "Allow",
        "Principal": {
            "AWS": "*"
        },
        "Action": "s3:GetObject",
        "Resource": "arn:aws:s3:::YourBucket name/*"
    }
]} 

It will resolve your problem.

Upvotes: 2

Related Questions