Can I broadcast an image with a page, instead of sending an ImageUrl?


I have images stored in a Sql Server database, and I want to display them on a web page.

The problem is, the Image control in ASP.NET has the property ImageUrl, which takes the value of a path to a folder which contains the image file. But I am drawing my image from a database table, and do not want to save the imge to the disk so I can provide the path. I'd rather stream the image directly to the page.

I'm having a hard time even picturing this (pun intended), and suspect that the only way this is going to get done is for the image to be temp-saved to a location and then pathed to an image control. But maybe I'm missing something?

Edited to Add:

This is for an accounting system where receipts for travel expenses are required to be presented for reimbursement. We are thinking of allowing users (we have 30,000 of them) to scan their receipts and store them in association with their reimbursement requests. Storing this in the file system is, I suppose, one way of doing it, with an index into the file system stored in a Sql Server table. But I've been asked to see if this could be done in Sql Server, and I can do this fine, but the display/report aspect is important. Reports need to be generated for these reimbursement requests, and I don't know how compliant Crystal Reports is with dipping into the file system. In short, it would be much easier to do this in Sql Server.

Have you considered using data URIs? A data URI allows you to embed data like images directly into your page. The image is encoded to base 64 and then included as the source of the <img> element in the HTML. You can read more about data URIs in general here.

The details of how to do this in C# are covered by this question and answer. The image element ends up looking something like <img src="data:image/png;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrS"/>.

The major issue with using data URIs for images is that older version of IE are not supported, or limit the size of the image. Here is documentation of the browser limitations of data URIs.