Upload file to amazon S3

Hello,

I have a Yii project that needs to upload a file to an amazon S3 bucket. It needs to be apart of a form for a model. When the model is saved it needs to put the file in the amazon S3 bucket. It doesn’t need to remember where it saved it because it will use this folder structure, /files/{user->id}/{file_name}. The file needs to be deleted when the model is too. I have spent most of my day trying to find a solution for this and I can not find one. Does anyone have any idea how to implement this one?

Thanks

I am also interested in a solution.

i have a feeling you have to save it locally and then move it from there to amazon.

also, if you’re just interested in the CDNish functionality S3 provides, you can use amazon’s CloudFront CDN and point it at your images/files on your server, and then in you application code create links that point to the equivalent CloudFront URLs, and CloudFront will request a given file/image once per day from your server, and then cache it across their servers which are strategically placed all over the world.

So if you’re just interested in high performance hosting of files and images, you can by-pass S3 completely and barely change your typical development pattern or write a single line of code. Basically, CloudFront is backed by an S3 bucket or–and this is a more recent feature–you can back it by your own external server.

One cool trick is you can point 10 CNames at Cloudfront, i.e. images1.site.com, images2.site.com, etc, and then in your application code when you generate a link to an image you can dynamically change the domain part of the url to the ones you configured in your DNS to point at cloudfront, and that allows for the up to 10 simultaneous connections browsers can have while downloading content. So rather than happening sequentially, the browser can download all at the same time.

So that all said, if you’re using S3 for something other than this, it should be pretty simple. Save it locally, and use their PHP library to send it to S3. If you’re trying to not save it locally first it may be more difficult, if not impossible, but i could be wrong.

Agreed, I did the same. You can do it directly with amazon with some classes but if you do it you loose the idea of checking the file that you upload before doing anything.

By the way, maybe this will be useful in the future : YiiAWS