How to set the permission on files at the time of Upload through Amazon s3 API

萝らか妹 提交于 2019-12-08 02:34:12

问题


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


回答1:


Add a header to your PUT request:

x-amz-acl: public-read




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/3863477/how-to-set-the-permission-on-files-at-the-time-of-upload-through-amazon-s3-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!