Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you store images for asp.net application?

Tags:

We are just upgrading our ASP.Net shop implementation (from simple one) to structure that should be more flexible. I am just looking for some options how to store images related to product. (there will be two types of images, thumb of the product and then full view images of the product). It should handle at least hundred products.

So far I am thinking about two options:
1) store images in db - images are loaded from Db into stream then into image (displayed by using IHttpHandler)
Pros
- The image itself is part of class, business object which we are working with in code behind
- one place to maintain product data
Cons
- memory consumption - traffic increase as we get the product data from other API

2) store images in file system - images are put in page as link
Pros
- none impact on memory as it is not stored in session, app cache.It is used like simple link
- no memory consumption
Cons
- needs to keep some name convention for images in File system (perhaps even some folder structure)
- more complicated maintenance of images

Is there any other suitable mechanism? What would you advice to use?

Personally I prefer images in file system, but it can be harder to maintain it as there are two separate places.

Thanks for any comment. X.

BTW: I can really imagine that in some stage the product will also have some videos or any other media that need to be displayed too. In this case Db is not really option, isn't it?

like image 453
Jaroslav Urban Avatar asked Jul 03 '09 09:07

Jaroslav Urban


People also ask

Where does asp net core store images?

As we know in asp.net core by default all the static files, such as HTML, CSS, images, and JavaScript have been stored within the project's web root director i.e wwwroot folder. We can also change the default directory by using the UseWebRoot method, for detail you can check how to change the default wwwroot directory.

Where are images stored in ASP NET MVC?

Images are stored in /Content/Images. Save this answer.


2 Answers

I made a system similiar to this. In my opinion, page load speed trumps all other considerations so I went with the 'store images on disk' option.

When images are added to the system, the original image is cropped and resized to the desired display size for browsing and a thumbnail is also generated. Three images are then stored to disk, the original, the display size and the thumbnail. Each one has a GUID generated for its filename.

(Imagine shopping on amazon, when you a browsing a list of products only the thumbnail is visible. When you inspect a product its display size is shown, and you can usually click on the image again to see the full size.)

I had a database table that looked a bit like this.

ID                int, PK
FullSizePath      varchar(128)
DisplaySizePath   varchar(128)
ThumbNailPath     varchar(128)
OriginalData      BLOB

I kept the original data in the db just incase there was an accident on the file server and the images got deleted, so they could all be re-generated. But this data is never pulled from the db during a page request.

like image 127
Kirschstein Avatar answered Nov 18 '22 22:11

Kirschstein


i think mixture of both is the best, for small critical image db is preferable and for large in amount and size file system is better

like image 37
Sadegh Avatar answered Nov 18 '22 22:11

Sadegh