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

Asked

Viewed 1,173 times

1

I have a folder created at the root of a project Web Api calling for Images. In localhost I record them as follows:

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

To display images in localhost i just need the same address. So, in the controller I create a Viewbag that receives the image address(Ex.: http://localhost:49730/Images/Product1.jpg) and with that code I can display her:

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

After having published in Windows Azure when saving the image it is not being recovered from url.

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

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

2 answers

3

In his ViewBag.Image do so:

/Images/Product1.jpg

Which means I’ve removed the address http://localhost:49730, is not accurate, so if in your Windows Azure the folder makes the same match you do not need to make any changes to the server, so default in both localhost how much in the Web Windows Azure

  • If I do so it takes the current address + the "/Images/Product1.jpg", the point is that I am accessing from another project, so I always add the localhost address of the web api (which is different from the localhost of my Asp.net mvc 5), and of course, before publishing in windows Azure I published the address of Azure in place of localhost, the other services work normally, only that the images are not being saved/recovered. Do you need to put this folder in a directory that exists for this type of situation?

  • Look I imagined that the folder was on the server with the images!!! That’s how I could do in my opinion...

1

As a Software Architect, I’d like to share.

No files hosted on application servers

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

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

It is where the file storage should be done. It gives super support for recording safely and cheaply, simplified backups, resources for external access for download and quick recovery.

Apart from the price:

  • Webapi: R$ 45 / GB / month
  • Azure Blob Storage: R$ 0,12 / GB / month

Wepapi is only for responding to HTTP requests. Persistence, leave to Blob Storage.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.