Libor Zapletal
Libor Zapletal

Reputation: 14102

Images in database or in project folder as resources

I am creating application in which I would have database which users can´t edit. It just have data and it shows to user. I found that I dont have to use localstorage I just can add database to project and it is readonly. So I did it and everything is ok. Now I want to add images to my app and I am not sure what is better way. I can every image add to folder, in database store path to image and It´s very easy and It can do now. Or I found that I can store image in database as image (byte[]). What is better? Would be images in database smaller? Would be loading of images faster? If images in database is better solution have can I easy way add images to my existing database? Is there any article to do this in winforms? Thanks

Edit: I'm glad that my question has so many answers and opinions. I want to explain more my needs. My application should have about 150 pictures and picture should be sized 150px and 100px. I want to app would work without internet connection. It could connect for updates but that´s all. Again thanks for all opinions :)

Upvotes: 5

Views: 1226

Answers (6)

Dave Becker
Dave Becker

Reputation: 1433

There are a lot of 'ifs', 'buts' and 'maybes' about where you put you put your images and I don't think there is a right or wrong way.

One thing worth mentioning is that if the application is business critical with high availability I would store them in the database, simply because the can be backed up with the rest of the data. Databases can be mirrored etc so having all the images treated as 'data' can be beneficial. Also if things get big and a web farm is employed and load balancers etc it helps when the images live in one place.

For me, I'd go with the database. But it all really depends on the scale of your application.

Upvotes: 2

Asken
Asken

Reputation: 8061

Nothing wrong with the answers already here but it really depends on what you are trying to accomplish and how it is currently set up.

Best would be to use a content delivery network for static images to ease the load of your web server.

You can serve from database or as resource file in file structure to your liking. If the images are static don't forget to add appropriate caching which for static content would be far future.

If you're rendering images I would definitely keep the images in the database to make it possible to access the images from any number of web servers.

If you want you can develop this further by keeping the images most recently used in memory or store on local filesystem so you don't have to get the file from the database every time.

Upvotes: 1

Asmodeo
Asmodeo

Reputation: 43

THe best option is to store your images on web folder, if you save them in DB, you will waste time retreiving them from DB because it takes more time

Upvotes: 0

shanabus
shanabus

Reputation: 13115

For our application, we found a hybrid approach worked best. We configured our SQL environment to support FILESTREAM and then imported all of our images. That gives us the flexibility of having the images 'in sql' while still storing the actual images to disk. Its a fast solution that may work well for you, too.

Upvotes: 3

MyKuLLSKI
MyKuLLSKI

Reputation: 5325

I personally would store all the images in isolated storage and in the database I would store the path to the image.

I would store all the images as a byte[] in the isolatedstorage

Upvotes: 1

srini.venigalla
srini.venigalla

Reputation: 5145

web folder. also think about remote loading them from a cloud server like Amazon S3 to free up access to your own server

Upvotes: 0

Related Questions