开发者

Uploading an image to the server or database?

开发者 https://www.devze.com 2023-03-27 21:32 出处:网络
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.

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


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.


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..


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号