Web Api 2 - How to return an image (MemoryStream from Azure Storage) from a HTTPGET without saving to disk? Web Api 2 - How to return an image (MemoryStream from Azure Storage) from a HTTPGET without saving to disk? angularjs angularjs

Web Api 2 - How to return an image (MemoryStream from Azure Storage) from a HTTPGET without saving to disk?


From the client side you don't need to use $http. You can simplify the process by using plain old HTML...

<img src="/api/PhotoSubmit/GetPhoto/2232" />

For dynamic images use JQuery like this...

$('#ImageLocation').html('<img src="/api/PhotoSubmit/GetPhoto/' + intID + '" />');

The web browser will automatically do the work of making an HTTP Request for the image, saving you all the complexity.

On the server side, you can use a process like these to load the file and stream it to the client. It's important that the Server code return the correct MIME type such as...

context.Response.ContentType = "image/png";

Resources:

ASP .Net Web API downloading images as binary

...and...

Display Image using ashx Handler