Page 1 of 1
Storing image pathes in a database
Posted: Thu Dec 12, 2013 12:39 pm
by bagi
Hi all,
I have an internet store and i need to store images of an item in db. I think that I need to store pathes, but not images (because there will be right load on db, i must to distribute it on db and fs). But how i can store that? I have a varuant with storing like "url;url", but it is a good way?
Re: Storing image pathes in a database
Posted: Thu Dec 12, 2013 1:20 pm
by requinix
If you have multiple servers then storing the images themselves in the database might be easier, otherwise you'd have to replicate the image files some other way (perhaps uploading them to an external source like Amazon S3).
Remember to never put multiple pieces of information into a column - no "url;url" but instead two rows each with one URL.
Storing them in the database: store the original filename (if you need it), size (is nice to have), type (JPEG, GIF, etc.), and raw data (in a BLOB or binary-type column)
Storing just the filenames: store the original filename (if you need it), the file path, and the size and type are optional (might be easier to get that information from the database than the files themselves)
Re: Storing image pathes in a database
Posted: Fri Dec 13, 2013 4:04 am
by bagi
Yes, you are right, butI dont understand about
Storing them in the database: store the original filename (if you need it), size (is nice to have), type (JPEG, GIF, etc.), and raw data (in a BLOB or binary-type column)
For what? Size column is needlessly, type i can get using regexp or db opportunities. And again: i don't need it. I will only output images on a page and small version of these images in search, only these purposes. Deleting, removing, editing of an image have to be easy
Re: Storing image pathes in a database
Posted: Fri Dec 13, 2013 12:42 pm
by requinix
True, you don't need to store the image size since you have the image data itself. Personally I would rather have the value there than have to do a calculation every time.
You need the size so you can send a Content-Length header. It is optional but a very good thing to do.