Serving images from Amazon S3 in PHP application
So it just occurred to me that o开发者_如何学Cnce I upload profile pics to S3, I have to figure out a way to keep track of the files. For example, if "susan" uploads 3 profile pics, I need to recall those 3 pictures and display it on her profile page if someone views her page. With that said, would the following work?
- User uploads picture from form
- Save file information (filename, user info, etc...) into DB and reference URL from S3
- Upload photos to S3
When displaying pictures, I'll query the DB for the info and display the images from S3 accordingly.
You should not store the full URLs in the database, just the file names. The URLs will all be consistent with this pattern:
http://s3.amazonaws.com/YOUR-BUCKET-NAME/YOUR-FILE-NAME
So you just need your constant bucket name and file name.
This way you can change how you serve the files and only change your app, not the data in the database (for example, if you start using CloudFront instead of direct S3 access).
ended up using GridFS from MongoDB.
精彩评论