Deepak N
Deepak N

Reputation: 1639

How do I make S3 file URL public using java code?

I have code to upload a file to S3, but I am not able to access the url of that file, for that I need to make the file url public. How can I make S3 URL public using JAVA in my AWS account and use from anywhere?

Thanks in Advance.

Upvotes: 0

Views: 396

Answers (1)

Sam Collins
Sam Collins

Reputation: 483

You can do this with just a bucket policy applied to the bucket. Then all files uploaded to the location should be public.

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

You can see more examples at https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html

Upvotes: 2

Related Questions