Is it better to database images or store them in a file?
Is it better to database images or store them in a file? For example, I have a large number of data records that contain both text and images. Is it best to write the text to a database and download the image to a file (C:/Website Images) and reference the location of the image (C:/Images Images/123456789.jpg) for each data record in the database? If so, would I use the following scripts?
//Write header
out.write("\"" + "IMAGE" + "\"" + ",");
//Write column
out.write( "C:/Website Images/" + session.getVariable( "IMAGE" ) + "," );
//Down image
session.downloadFile( "http://thumbs.website.com/pictures/thumbs/" + session.getVariable ("IMAGE"), "C:/Website Images/" + session.getVariable ("IMAGE"), 5, true);
Thanks in advance for your help.
Sorry for the delays. Busy
Sorry for the delays. Busy busy.
Databases often support a "blob" data type which can hold images, but usually there's not a speed benefit for that. You *could* do it that way, but usually "binary" data types (like images) are really simple enough to keep on your hard disk.
That being said, yes-- you would most likely want to keep a reference to the file location in the databases. You might not have to keep the "C:/Website Images/" part there if you can imply that much. For instance, if you were ever to change your folder location, it'd be a pain in the neck to change the database entries. Whereas if you kept the database references relative, you could easily change folders with much trouble.
Your scripts look pretty good for getting the image-- all that would remain is saving the file reference to a database, if you so choose. That would make for good fast lookup time.
Hope that provides some insight :)