Amazon S3 Image for 404
I've setup Amazon S3 to host my user avatars, but the problem I'm having is how to display the default avatar if a user hasn't uploaded a photo. Is there a way to return an image on 404?
I want to minimize overhead and have it so a user image has a url l开发者_开发知识库ike this:
http://example.s3.amazonaws.com/avatar/52752545b960b3181226a2f346e2f466714_64.jpg
Where the hash before '_64' is the userid hashed with a salt, and '64' being the dimension. This way I don't have to check on my server whether the user has uploaded an photo or not on every avatar display.
Thanks in advance
Here is a real-world example that I use. The source image lives on s3, pulled from a CNAME.
So example:
<img class="image" src="http://cache03.zoomphoto.ca/i/15665/thumbs/t_15665-101- 15032855.jpg" hspace="1" vspace="1" alt="" onerror="this.src='http://static.zoomphoto.ca/images/processing_thumb.jpg';">
So you show the image, if nothing is available (onerror), then show this.
No but if the paths to the avatars are saved in a database, you could an "if" statement to choose whether to display the image from Amazon S3 or use a default avatar.
精彩评论