How to create a Database Image Bank in MVC

Also available in portuguese

The goal is use a database to store images “Image Bank” and use MVC to call those images using custom routes. The URL must be something like that: “imagebank/sample-file” or “imagebank/32403404303“.

The MVC Controller/Action will get the image by an ID “sample-file” or “32403404303” and find out on some cache and/or database and display the image. If exists in cache, get from cache if not get from database.

So in html we can call the image like that:

<img src="/imagebank/sample-file" />

If you want to use another url for instance “foo/sample-file” you can change imagebank route name in web.config.

If you want do not display the image and just download the file, use that:

You can improove the solution to all kind of files.

This is it. I hope it helped.

How to create a Database Image Bank in MVC

Image Bank in MVC: Questions, suggestions and feedbacks will be appreciated. Good luck!

Do complete download of the source code on github.

Try demo online of that application on codefinal.
About the Author:
He works as a solution architect and developer, has more than 16 years of experience in software development on several platforms and more than 14 years only for the insurance market.