将图像上传到服务器或数据库?
我正在尝试为网络应用程序的用户实现“个人资料页面”。 我希望用户能够上传其个人资料的图像。
我的问题是,这应该如何实施?
我应该将图像作为 blob 上传到数据库中,还是将图像上传到服务器中并将路径存储在数据库中?
对于用户个人资料来说,图像的最佳尺寸应该是多少?
我正在使用以下内容。 1.MySQL 5.5.11 2. 春天 3 3. hibernate
我们将不胜感激您的帮助。
问候 阿多福
I am trying to implement the "profile page" for the user of the web application.
I want the user to be able to upload the image for their profile.
My question is that how should this be implemented?
Should I upload the image in the database as a blob, or shall I upload the image in the server and store the path in the database?
What should be the optimum size of the an image, for user profile?
I am using the following.
1. Mysql 5.5.11
2. Spring 3
3. hibernate
Your help will be appreciated.
Regards
Adofo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将图像作为文件存储在服务器上,并将图像 ID 或路径存储在数据库中。如果您这样做,则只需为已删除的用户做更多的文件清理工作。 40-80K 的 JPEG 图像大小是“个人资料图片”的合理目标。对此的真正限制是您的服务器性能和流量。
Store the image as a file on your server and store the image ID or path in your database. If you do it this way, you have to just a little more work on file clean-up for deleted users. A JPEG image size of 40-80K is a reasonable target for a "profile picture." The real constraints on this are your server performance and traffic volume.
Mysql中blob数据类型的目的是完成“在数据库上存储图像”。如果您的图像数量较少(假设<100),我会说,将其存储在数据库中。如果没有,请尝试将图像存储在目录中(WEB_ROOT 下)并配置您的网络服务器以直接提供图像而不冻结数据库(通过检索)。
希望有帮助..
The purpose of blob datatype in Mysql is to accomplish "Storing image on database". If you have less number of images (lets say <100), I would say, store it in a database. If not, try to store the image in a directory(under WEB_ROOT) and configure your webserver to directly serve the image without freezing the database (by retrieval).
Hope that helps..
我听过关于存储图像的争论,并且过去也曾想过。我个人喜欢存储在数据库中的想法。我觉得出错的空间较小(即,意外删除图像目录位置,并且您的图像/数据库条目不同步。
我认为宽度不超过 100 或 150 像素的个人资料图片在 72 dpi 下就足够了。您可以要求上传的尺寸为这些尺寸,或者接受任何内容并通过“预览”将其图像保存在新尺寸中来操作它,
这只是我的想法。
I've heard arguments for storing images from both sides of this and have wondered myself in the past. I personally like the idea of storing in a database. I feel like there's less room for error (i.e., accidentally deleting the image directory location and your images/database entries become out of sync.
I think profile pictures of no more than 100 or 150 pixels wide is sufficient with 72 dpi. You can either require the uploads to be those dimensions or accept anything and manipulate it for them with a "preview" of what saving their image in the new dimension would look like.
Just my thought.