469,647 Members | 1,677 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

Storing images in folder or database?

Hello,

I am working on an ASP.NET based website project. Without going into
much detail; One of the function on this website will be the
possibility to upload images via a ASP.NET form to the webserver. These
images can then be shown on to webpages throughout the site.

What would be the best way of storing these images? Just by saving them
in a folder on de webserver or in a database?

What are the advantages and disadvantages of both working methods?

Thanks.

Nov 23 '05 #1
4 4407
I have faced this problem twice and each time I elected to put them in the
file system and then have some table that tracks filenames and associates to
an object in the database. Obviously you lose referential integrity but it
is possible to write a little program that checks that a row in the table
exists for each file name and a filename exists for each row in the table.

On one project we have 12GB of files and the database is only 500meg in
size. The management of the DB would have been more difficult if all of the
files were stored in it.

If you have a lot of files it is important to choose a good naming scheme
and directory structure. Our scripts automatically create a directory per
year per month per day of month. ie Files\2005\04\31\ In that way no one
directory becomes too large.

Backing up the data is also a breaze - xcopy.

You have to structure the transaction during the upload. If you start a
transaction, wait for the file to upload, add it to the database, add it to
the file system and then commit the transaction then you will have some long
running locks. Be careful that if the file does not upload correctly then
everything is clean up as expected.

There is some more code to write to manage the files and directories and the
database but it is a solution that works well.

I hope this helps. Feel free to contact me if you want more information (or
even code)

Dave A

"IkBenHet" <ik********@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Hello,

I am working on an ASP.NET based website project. Without going into
much detail; One of the function on this website will be the
possibility to upload images via a ASP.NET form to the webserver. These
images can then be shown on to webpages throughout the site.

What would be the best way of storing these images? Just by saving them
in a folder on de webserver or in a database?

What are the advantages and disadvantages of both working methods?

Thanks.

Nov 23 '05 #2
I have faced this problem twice and each time I elected to put them in the
file system and then have some table that tracks filenames and associates to
an object in the database. Obviously you lose referential integrity but it
is possible to write a little program that checks that a row in the table
exists for each file name and a filename exists for each row in the table.

On one project we have 12GB of files and the database is only 500meg in
size. The management of the DB would have been more difficult if all of the
files were stored in it.

If you have a lot of files it is important to choose a good naming scheme
and directory structure. Our scripts automatically create a directory per
year per month per day of month. ie Files\2005\04\31\ In that way no one
directory becomes too large.

Backing up the data is also a breaze - xcopy.

You have to structure the transaction during the upload. If you start a
transaction, wait for the file to upload, add it to the database, add it to
the file system and then commit the transaction then you will have some long
running locks. Be careful that if the file does not upload correctly then
everything is clean up as expected.

There is some more code to write to manage the files and directories and the
database but it is a solution that works well.

I hope this helps. Feel free to contact me if you want more information (or
even code)

Dave A

"IkBenHet" <ik********@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Hello,

I am working on an ASP.NET based website project. Without going into
much detail; One of the function on this website will be the
possibility to upload images via a ASP.NET form to the webserver. These
images can then be shown on to webpages throughout the site.

What would be the best way of storing these images? Just by saving them
in a folder on de webserver or in a database?

What are the advantages and disadvantages of both working methods?

Thanks.

Nov 23 '05 #3
Hello Dave,

Thanks for your clear answer! So, basically it is integrity that you
can lose if the script is not structured in a good way. Of course some
reference code is welcome. Was is all done in ASP.NET? You can sent it
to my e-mail adres.

Thanks.

Nov 23 '05 #4
Hello Dave,

Thanks for your clear answer! So, basically it is integrity that you
can lose if the script is not structured in a good way. Of course some
reference code is welcome. Was is all done in ASP.NET? You can sent it
to my e-mail adres.

Thanks.

Nov 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Benoit St-Jean | last post: by
6 posts views Thread by bissatch | last post: by
4 posts views Thread by Rednelle | last post: by
reply views Thread by IkBenHet | last post: by
9 posts views Thread by Adam J Knight | last post: by
9 posts views Thread by Wayne Smith | last post: by
2 posts views Thread by Spondishy | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.