How to save images for asp.net application?

We simply update our ASP.Net store implementation (from simple) to a structure that needs to be more flexible. I'm just looking for some image storage options related to the product. (there will be two types of images, the thumb of the product, and then a full view of the product image). He must process at least a hundred products.

So far I am thinking of two options:
1) store images in db - images are downloaded from Db to the stream, and then to the image (displayed using IHttpHandler)
pros
- The image itself is part of a class, a business object, with which we work in the code behind which there is one place for storing product data
Minuses
- memory consumption - increased traffic, because we get product data from another API

2) store images in the file system - images are placed on the page as a link
pros
- does not affect memory, since it is not saved in the session, application cache. It is used as a simple link.
- lack of memory consumption
Minuses
- you need to save some kind of agreement on the names of images in the File system (perhaps even in some folder structure)
- more sophisticated image maintenance

Is there any other suitable mechanism? What would you recommend using?

Personally, I prefer images on the file system, but it can be harder to save, because there are two separate places.

Thanks for any comments. X.

By the way: I can really imagine that at some point the product will also have some videos or any other media that should also be displayed. In this case, Db is not really an option, is it?

+4
source share
5 answers

I made a system like this. In my opinion, the page loading speed exceeds all other considerations, so I went with the option "save images to disk".

When images are added to the system, the original image is cropped and resized to the desired screen size for viewing, and a thumbnail is created. Then the three images are saved to disk, original, display size and thumbnail. Each of them has a GUID generated for its file name.

(Imagine buying on Amazon when you look at a list of products, only a thumbnail is displayed. When you check a product, its display size is displayed, and you can usually click the image again to see the full size.)

I had a database table that looked something like this.

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

I saved the original data in db only if an accident occurred on the file server and the images were deleted, so all of them can be generated. But this data is never retrieved from db during page request.

+4
source

I think the mixture of both is the best, for a small critical image, db is preferable and for a larger one in a dimensional and dimensional file system it is better

+1
source

You must have hidden something. You can save the main image in the / db file system, but you can generate thumbnails on the fly programmatically, which will reduce disk space.

0
source

In examples like your example where I work, we usually save images to disk, and then save the file name record in db.

Then, when you have db of your products, you can search and dynamically upload the image to the product.

It is also not bad if you have an administrative system for adding / removing / editing products.

I guess this is between your two original sentences, you can even save all the images in the same directory if you want.

0
source

If you are using MS SQL 2008, you have the option function FILESTREAM .

Here is the gist, but you should read the entire white document:

FILESTREAM is a new feature in SQL Server 2008. This allows structured data to be stored in a database and related unstructured data (that is, BLOBs) that must be stored directly in the NTFS file system. You can then access BLOB data through the high-performance streaming of the Win32® API, instead of paying a performance penalty when accessing BLOB data through SQL Server.

FILESTREAM maintains transactional consistency between structured and unstructured data at all times, even allowing timely recovery of FILESTREAM using log backups. Persistence is automatically saved by SQL Server and does not require any user logic in the expression. The FILESTREAM mechanism does this by supporting the equivalent of a log database transaction, which has many management requirements (described in more detail in the "Configuring FILESTREAM Garbage Collection" section later in this white paper). The combination of transaction log databases together with the FILESTREAM transaction log allows FILESTREAM and structured data. transactionally restored correctly.

0
source

All Articles