rid00z
rid00z

Reputation: 1616

AWS S3 uploading directly and automatically making file public

I'm uploading files via a htmlpage directly using CORS, it's all working fine. The problem is the files aren't public read, so I would like to make automatically public read.

Here's the policy I think should do it but doesn't work.

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

Thanks for your help in advance.

Upvotes: 1

Views: 943

Answers (1)

Brenton
Brenton

Reputation: 124

Bucket policies do not apply to objects "owned" by others, even though they are within your bucket, so the only way to do this is to make public during the upload using a request header.

request.AddHeader("x-amz-acl", "public-read");

Upvotes: 3

Related Questions