How to use folder to store images in a Api Web project published in Windows Azure?

1

I have a folder created at the root of a Web Api project named Images . At localhost I write them as follows:

 File.WriteAllBytes(HttpContext.Current.Server.MapPath("~/Images/") + image.Name, image.Image);

To display the images in localhost I only need the address of the same. So, in the controller I create a ViewBag that receives the image address (Ex: http://localhost:49730/Images/Product1.jpg ) and with this code I can display it:

<a href="@ViewBag.Image">Abrir Imagem</a>

Once you have published in Windows Azure when saving the image, it is not being retrieved from the url.

What needs to be done other than localhost to work on Windows Azure ?

Update: before publishing in windows azure I have published the azure address in place of localhost, other services work normally, only the images that are not being saved / recovered.

    
asked by anonymous 03.07.2014 / 01:38

2 answers

3

In your ViewBag.Image do so:

/Images/Product1.jpg

In other words, I removed the address http://localhost:49730 , it does not have precision, so if in your Windows Azure folder the same match does not need to make any changes on the server, thus becoming standard in both localhost and Web Windows Azure / p>     

03.07.2014 / 02:15
1

As a Software Architect, I would like to share.

  

Do not host files on application servers

This is a bad practice, and should be avoided to the extreme.

There are specific services for mass data persistence, such as image files, office documents, and more: Blob Storage .

This is where file storage should be done. It gives super support for safe and low cost recording, simplified backups, external access features for download and fast recovery.

Outside the price:

  • WebAPI: $ 45 / GB / month
  • Azure Blob Storage: $ 0.12 / GB / month

WepAPI is just for responding to HTTP requests. Persistence, leave it for Blob Storage.

    
02.12.2015 / 19:15