How to set the permission on files at the time of

2019-05-23 21:47发布

Is there any way to set the file permission at the time of uploading files through Amazon S3 API.

In my current solution i am able to upload the file on my bucket but i can not view the file through the URL which is mentioned in the file properties section. It is opening when i am passing access keys in query string.

Is there any settings required in Amazon S3 or i need to set the permissions to all the file at the time of upload.

Thanks in Advance.

Kamal Kant Pansari

3条回答
我想做一个坏孩纸
2楼-- · 2019-05-23 21:56

Add a header to your PUT request:

x-amz-acl: public-read

查看更多
Explosion°爆炸
3楼-- · 2019-05-23 21:56

In C# when you create a response object of >mazon then in response method you will find Addheader.

You need to set header as

response.Addheader("x-amz-acl","public-read");

Amazon providing these methods in its web services API kindly refer that.

查看更多
小情绪 Triste *
4楼-- · 2019-05-23 22:02

You can also use Bucket Policies feature.

Here is an example of bucket policy that instructs amazon s3 to make all of the files publicly available, including new files you will upload:

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

Replace your.bucket.name with your actual bucket name

You can view and edit Bucket Policies with S3 Browser Freeware. You can find more Bucket Policies examples here.

查看更多
登录 后发表回答