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

I have my photos on Amazon S3. Images are private and not public, so I can not show them the direct link s3.amazonaws/bucket_name/key_name/image_name.jpg

I know the image names on Amazon S3. How do I show, for example, Amazon S3 flower.png and house.png images on my site with PHP?

+3
php amazon-s3 amazon-web-services
source share
2 answers

If you do not want to publish your file, here is the procedure.

  • Make sure your S3 bucket is closed. Only authorized and authorized calls are allowed.

  • on the server side, when rendering the page, they generate links to the S3 object, which includes the signature. The signature will be calculated from your access and private key and will inform S3 that the call should be allowed

S3 Signed URL is easily generated from our SDK. For PHP just check out the document http://docs.aws.amazon.com/aws-sdk-php/guide/latest/service-s3.html#creating-a-pre-signed-url

  1. on the web page, when the user clicks the signed URL, the browser will be redirected to S3. S3 verifies the signature and - when correct - receives the object
+5
source share

The simplest thing is to make them public in s3, at least read-only.

If you do not want them to be publicly available on s3, for some reason you could add a cloud distribution that will serve the images from your s3 bucket, and you can provide cloud file access without having to make public images in s3.

This link shows you how to do this:

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html

+1
source share

All Articles