Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon S3 Access image by url

Tags:

amazon-s3

I have uploaded an image to Amazon S3 storage. But how can I access this image by url? I have made the folder and file public but still get AccessDenied error if try to access it by url https://s3.amazonaws.com/bucket/path/image.png

like image 787
SiberianGuy Avatar asked Aug 07 '11 20:08

SiberianGuy


People also ask

How do I show an image from my Amazon S3 on my website?

Easiest thing to do is make them public in s3, at least read-only. If you don't want them to be public on s3, for whatever reason, you could add a cloudfront distribution that will serve the images from your s3 bucket, and you can give cloudfront access to the files, without making the images public in s3.

Why is S3 object URL Access Denied?

If you're trying to host a static website using Amazon S3, but you're getting an Access Denied error, check the following requirements: Objects in the bucket must be publicly accessible. S3 bucket policy must allow access to the s3:GetObject action. The AWS account that owns the bucket must also own the object.

Can I access S3 bucket from browser?

In short, if you set x-amz-acl: public-read on a file then you can access it as https://s3.amazonaws.com/bucket-name/path-to-file . No need for enabling website hosting, unless you want the pretty hostname and support for index and error documents.

What is the valid URL for Amazon S3 bucket access?

An S3 bucket can be accessed through its URL. The URL format of a bucket is either of two options: http://s3.amazonaws.com/[bucket_name]/ http://[bucket_name].s3.amazonaws.com/


2 Answers

This is an older question, but for anybody who comes across this question, once I made the file public I was able to access my image as https://mybucket.s3.amazonaws.com/myfolder/afile.jpg

like image 54
akotian Avatar answered Sep 20 '22 02:09

akotian


in my case i have uploaded image privately so that i was unable to access. i did following code

const AWS = require('aws-sdk') const myBucket = 'BUCKET_NAME'   const myKey = 'FILE_NAME.JPG'   const signedUrlExpireSeconds = 60 * 1   const s3 = new AWS.S3({     accessKeyId: "ACCESS_KEY_ID",     signatureVersion: 'v4',     region: 'S3_REGION',     secretAccessKey: "ACCESS_SECRET"   });    const url = s3.getSignedUrl('getObject', {       Bucket: myBucket,       Key: myKey,       Expires: signedUrlExpireSeconds   })    console.log(url) 
like image 37
Renish Gotecha Avatar answered Sep 21 '22 02:09

Renish Gotecha