0

This is my first question on Stackoverflow.

I'm facing an architecture issue more than a programming one.

I'll explain the topic : I'm working with Microsoft Azure Cloud Service solution.

I have a WorkerRole which encrypts uploaded pictures and stores them in a Blob.

Then I have a WebRole with which I want to display this picture in a browser, within an image controller.

I managed to get an encrypted picture from a blob to local storage and to decrypt it.

At this point, I looked how to display pictures stored in WebRole LocalStorage when I found this. The answer explains that it's a bad idea to use local storage to serve picture since each request can hit different instances of my webRole.

So, here i'm stuck, how can I serve my decrypted pictures to my image controller without having an unencrypted copy of my picture in the blob ?

Solution Define a web handler which download picture from blob to webrole, then decrypt it and return this.

public class Images : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
        {
            String imgPath;
            String imgName = context.Request.QueryString["imgName"];
            imgPath = getFromStorage(imgName);
            context.Response.ContentType = "image/png";
            context.Response.WriteFile(imgPath);
        }
}

In your image web control :

<asp:Image ID="imgViewer" ImageUrl="Images.ashx?imgName=mypicture.png"/>
Community
  • 1
  • 1
Akoma
  • 11
  • 3

2 Answers2

0

I'm not sure why you are encrypting the file, but if you have to do this then maybe this answer will help: Can an ASP.NET MVC controller return an Image?

I personally store private documents in a private container. Then you can grant access using an SAS to the document for a specified period of time.

Here is a link with the same concept: http://blogs.msdn.com/b/eugeniop/archive/2010/04/13/windows-azure-guidance-using-shared-key-signatures-for-images-in-a-expense.aspx

I have a form of this in a production environment for actual documents.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Rogala
  • 2,679
  • 25
  • 27
  • thx but I was already aware of SaS stuff. My pictures must be encrypted on the storage. – Akoma May 04 '15 at 08:19
  • Fair enough, you can handle your encryption in the controller and then return the image. The first link should allow you to do this. – Rogala May 04 '15 at 20:29
  • Sur, but I not using MVC and by "image controller" I mean . Anyway, thx for your reply but I found the solution. I will edit my question with the solution – Akoma May 06 '15 at 06:43
0

It is true that each request can hit a different instance of the web role, but in this case it seems you are downloading and decrypting within the same request. You could just delete the image from local storage after the request is processed. The next request would hit a different instance, which would similarly download, decrypt, serve and delete.

Atul Sikaria
  • 296
  • 1
  • 8