Yesod - 用户个人资料图片应该存储在静态目录中吗?

Yesod - Should user profile pictures be stored in the static directory?

目前用户上传的头像保存在/static/avatars/{upload-date}。然后,我通过存储在数据库中的信息为图像生成 StaticR 路由(它们是在 运行 时间添加的,因此 StaticR 路由尚不存在)。

我遇到的问题 运行 是当用户更新他们的个人资料图片时,由于静态文件的缓存,他们仍然得到旧的。有什么办法解决这个问题还是我应该将图像存储在其他地方?如果是这样,那么我该如何访问 /avatars/{upload-date}/{userid}.png 中的图像?

我知道我可以按照 /avatars/#Day/#UserId 的路线创建路线,但我不确定如何在其后附加“.png”或“.jpg”。或者我会为处理程序函数编写什么。

I know I could create a route along the lines of /avatars/#Day/#UserId but I'm not sure how I would get the ".png" or ".jpg" appended to th

您的 url 没有必要以 pngjpeg 扩展名结尾。您只需确保您的内容类型 header 设置正确。

Or what I would write for the handler function.

这很简单。如果您要提供 png 图片,那么您所要做的就是使用函数 sendFile and typePng 来提供它们:

myAvatarHandler = sendFile typePng "/home/yesod/static/avatars/day/userid.png"

同样在您的示例中,请确保存储上传的时间戳并根据该时间更改您的 url。否则将缓存同一天更新的两张头像。