Fairly straightforward question, I have images stored in my database as varbinary and would like to provide a link to these images rather than displaying them on the website. When a user clicks the link he/she should be able to download the image.
Fairly straightforward question, I have images stored in my database as varbinary and would
Share
An image is served in response to a request.
You need to create an HTTP handler to receive requests for these images.
A handler is an executable available at a specific URL which can respond to your request; in this case, by serving the binary data of an image. An ASPX page is a valid handler, though there are more efficient handler types for images.
The handler should do a few things:
Response.BinaryWrite()to send the binar data to the client.Note that if you are using ASP.Net MVC, you can use a controller as your handler.
An alternative method is to base 64 encode the bytes and embed them directly in the image tag.
This is a useful technique for small images or when the expense of multiple requests is very high.
See: http://en.wikipedia.org/wiki/Data_URI_scheme
More reading: