0

我已经设置 Amazon S3 来托管我的用户头像,但我遇到的问题是如果用户没有上传照片,如何显示默认头像。有没有办法在 404 上返回图像?

我想最小化开销并拥有它,以便用户图像具有这样的 url:

http://example.s3.amazonaws.com/avatar/52752545b960b3181226a2f346e2f466714_64.jpg

'_64' 之前的散列是用盐散列的用户 ID,'64' 是维度。这样我就不必在我的服务器上检查用户是否在每个头像显示上都上传了照片。

提前致谢

4

2 回答 2

4

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.

于 2011-11-19T00:34:42.273 回答
2

不,但如果头像的路径保存在数据库中,您可以使用“if”语句来选择是显示来自 Amazon S3 的图像还是使用默认头像。

于 2011-06-14T02:59:27.433 回答