开发者

Simple image delivery with AWS CloudFront and PHP?

开发者 https://www.devze.com 2023-04-01 02:26 出处:网络
I just started playing around with Amazon S3 and CloudFront and have managed to create a S3 Bucket and a Distribution on CloudFront.

I just started playing around with Amazon S3 and CloudFront and have managed to create a S3 Bucket and a Distribution on CloudFront.

My purpose is to use CloudFront for simple image / css delivery from edge locations - so I'm looking at the most basic of AWS functions.

I uploaded some images in the S3 bucket and when I tried accessing the same for testing purpose with http://xxx.cloudfront.net/image.jpg I get the following error:

<Error>
    <Code>AccessDenied</Code>
    <Message>Access Denied</Message>
    <RequestId>ABCD1234</RequestId>
    <HostId>
        xxxxx
    </HostId>
</Error>

I'm guessing I need to verify myself before I start delivering the content? I've grabbed the AWS-PHP SDK but then am at a loss as to what to do. All examples provided on the AWS Docs are for more complex functionality... there doesn't seem to be a straight-cut code sample for simple image delivery.

Has anyone here set this up before? How did you go about it?

开发者_如何学C

My website is written with PHP.

Any help will be much appreciated.

Thanks,

m^e

UPDATE

The section on Basic Links in this AWS Doc page says that I can access my uploaded resource in the http://xxx.cloudfront.net/image.jpg format.

However, when I do that I get that Access Denied XML dump.

So I went back to the S3 bucket, right-clicked on the image and clicked Open. It opened up the image in a popup with the following link format:

http://xxx.cloudfront.net/1st-open-house-jan-2011.jpg?AWSAccessKeyId=yyy

Whenever I try polling my images in this format (including the AccessKey) it seems to work. Without AccessKey in the URL, nada.

Does that mean, I've to include that access key in every single image request throughout my website? Or is there any other means of pre-verifying a request at a single point and then on keep loading images normally, minus the access key in the url?


Why don't you make your images public? I can imagine you want to keep video or audio private, but images? They can be grabbed anyway, so why bother protecting them? Just set permission Everyone to Read and the problem is solved.

i hope this helps?


Ah ha, I think I know this one, mainly because I have been researching it myself.

The question is answered in the following 2 questions on stackoverflow.

How do I download a file with php and the amazon s3 sdk Force download with php on amazon s3

It is to do with setting Content-Type and Content-Disposition in your call. But as John R mentioned, for images, css and js I would personally just make them public.

0

精彩评论

暂无评论...
验证码 换一张
取 消