Posted By: brownsoft | Jun 23rd, 2005 @ 3:56 PM
page 1 of 1
Comments: 13 | Views: 11061
I just recently built a app for fun that loads images from SQL 2000(MSDE) and displays them on a form kind of like you see one done via Access.

Anyway, I was reading elsewhere that suggess that you just store the url to the image in the database and the image is stored on the harddrive.  I was wandering what people think which is the fastest and easiest to do.


PerfectPhase
PerfectPhase
"This is not war, this is pest control!" - Dalek to Cyberman
depends on what you really want to do.   URL is definatly the easiest and fastest if you let IIS server the image up for you directly.  I have one app for example that stores the image in the DB because the security sytem does not map to NTFS ACL's very well and it was easier to secure if the image was stored in the DB.  It's also easier to handle having the app running on multiple servers as you don't have to mirror the files to each web server, just let SQL server replication handle it for you. 

Many pro and cons for each, give us a bit more detail on your app (i've assumed it was ASP.NET) and we can give you a better answer.
 
Stephen. 
PerfectPhase
PerfectPhase
"This is not war, this is pest control!" - Dalek to Cyberman
On the server for sure, you just have to watch out for name collisions when saving the uploaded files to disk.

Stephen
W3bbo
W3bbo
The Master of Baiters
PerfectPhase wrote:
On the server for sure, you just have to watch out for name collisions when saving the uploaded files to disk.

Stephen


I got around that by saving all uploaded files as GUIDs.

When I had an upload form with multiple users, I would rename the uploads to GUIDs like W3bbo said and then store the original name as well as some other information in a table so when I presented the data, the user would see the file with its original name.

PerfectPhase
PerfectPhase
"This is not war, this is pest control!" - Dalek to Cyberman
Yep, thats what I did, and created the thumbnails while I was at it.  The only downside is you lose the proper names if a user does right-click save as.

Stephen.
hardball
hardball
Let's Go
hello everyone, i'm new here. hope to come back often Smiley

i always use a separate file for retrieving an image,
say, you want to display an image that is stored with an ID 1297 in the DB,
<img src="/getimage.aspx?id=1297">
blah blah.
you get the idea.
then in the getimage.aspx you are very flexible as to what you do, get the binary from the db, or get the reference only and read from the disk?
depending on your images, you might store the pics on the disk, since the performance will go down appr. 30-40%, especially with large files. besides, holding the reference is very little overhead (e.g. naming conventions) compared to holding the binary, but has lots of advantages, most of all speed.

just throwing in my 2 cents Smiley
PerfectPhase
PerfectPhase
"This is not war, this is pest control!" - Dalek to Cyberman

While we are talking, it's beter to use an ashx handler for stuff like this as you then you do not have the overhead of all the page framework.

Also while I store the details for a page in the db and use that for building lists etc, if the files are on disk, most of the time i'll write out the direct link to the file on disk in things like <img> tags.  Let IIS do what it really good at and serve the file directly.

Stephen.

hardball
hardball
Let's Go
PerfectPhase wrote:


most of the time i'll write out the direct link to the file on disk in things like <img> tags. 



that's perfectly fine and i agree that's the easiest and fastest way to do that.
if you think further though, how would you generate different sizes (thumbnails, medium size, fullsize) of the same picture (like some online albums do)...
using an separate image fetcher will let u do all of this quite easily: getimage.aspx?id=123&w=120&h=120&q=60
where q is quality (jpeg 1-100), which can be very low for thumbnails, and high for the downloadable fullsize picture, for instance.
so there are many pretty neat tricks u can think of (cropping?, watermarks?, etc.)
W3bbo
W3bbo
The Master of Baiters
dynamic image generation per request entails a massive performance overhead.

It is far, far, better to perform all processing on an image upon being uploaded, although this does come at a slight disadvantage as far as disk-space is concerned.

Note that requesting a JPEG directly is a lot faster than routing it through a database and returning some binary stream.
PerfectPhase
PerfectPhase
"This is not war, this is pest control!" - Dalek to Cyberman
W3bbo wrote:
dynamic image generation per request entails a massive performance overhead.

It is far, far, better to perform all processing on an image upon being uploaded, although this does come at a slight disadvantage as far as disk-space is concerned.


When doing something like this, I cache the generated files to the DB/disk on first request rather than when uploading.  I also tend to limit the image size to several common sizes, just makes the whole lot easier to manage, and you can cull older images from the cache and have them recreated as needed.

Stephen.


staceyw
staceyw
Before C# there was darkness...
I know you asked for 2000, but here is way to upload and download in 2005.  The 2000 should be close but does not have the VarBinary data type.  MSDN has the code for 2000.  Here is my 2005 version:

http://spaces.msn.com/members/staceyw/Blog/cns!1pnsZpX0fPvDxLKC6rAAhLsQ!404.entry
I am using ASP.net and SQL2000 as my database.
Can anyone guide me with coding if i want to upload my flash image file to a folder in server and keep my url of the flash in database.

How do I actually connect the flash file in server and the url Perplexed