Developing an application in which users have to upload images. I have not really got much experience with file uploads in an application so I am wondering what the best way is for storing images which are uploaded by users to the file system.
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
closed as primarily opinion-based by Scant Roger, GlenH7, Snowman Dec 8 '15 at 18:34
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.
A good, basic starter strategy is like this:
Areas of enhancement:
Images are just files, so you could store them as-is, as you would store any other file.
However, you may want to transform them a little. For example, most digital cameras these days produce absurdly high resolution files, e.g. 2000 pixels across. Most users don't know how to shrink them to something more manageable, and even if they did, they don't have the time (or can't be bothered.) So you may want to allow people to upload large images, then shrink them.
Also, what will you do with the images? Display them on a web page? There are only certain formats that work on a web page, e.g. if someone uploaded a TIFF image, you might want to convert it to JPEG or PNG.
Finally, you might want to increase compression. If someone sends you an image that's a reasonable resolution, but they're turned all the "quality" options up to 11, it will still be a big file. You might want to compress it more to make it a smaller file.
A final consideration: if you're going to do any image manipulation, you might want to put all images into the same format, e.g. JPEG at a certain resolution and compression level, so your image manipulation only has 1 format to deal with.
The storage strategy should, in most cases, follow from the conceptual design of the site that requires image storage, and the expected number of users. We'll need more information, I think; are you creating a site like Photobucket or Flickr, designed primarily to be an image-hosting site? Or are the images a secondary concern, such as being attachments to messages? How many images do you foresee having to store? How many users will this system have?
Two popular strategies I know of and have used involve a SQL database, to provide better concurrency than a flat file system. You have a table, representing the images in the DB. That table then either has a "BLOB" (binary large object) column that stores the actual byte data of the image, or a string that holds the path to the image in a flat file system elsewhere. Either way, scanning for data about images is highly parallelizable. Storing images on disk is more straightforward, and reduces the size of the DB, but lowers performance in high user-count situations. Storing images as DB data is the opposite.