Ace Supriatna
Ace Supriatna

Reputation: 235

What folder in asp MVC Web Sites are accessible to store and retrieve files apart from App_Data when hosted in Azure Web Sites?

I just finished my asp MVC 5 website that has capability to upload, display and download file. While offline, I uploaded the files to a random foldes inside the root directory like ~/assest/images etc and worked great.

Then I deployed to the windows Azure Web site service, and started to realize that the root directory is not accessible anymore. I started to do researches and found out that only App_Data is accesible to store files. Alas, it is not a good solution and we cannot retrive the file, like image, to be shown in razor view.

I also found BLOB Storage, which seems to be great, but there is no sufficent tutorial, that I could not succeed to use one. Most of them are for MVC web roles, while in my case it is MVC WEB SITES.

Now, I want to find another alternative, is there any special folder, or workaround to make one folded inside the root directory that can store files and retrieve them? in fact, my application needs only a few pictures and PDF to store.

thanks

Upvotes: 1

Views: 1778

Answers (3)

Zain Rizvi
Zain Rizvi

Reputation: 24636

If you do not expect to need much storage you can store your files anywhere in your site's folder. I'm not sure why you're seeing an error if you upload files to anywhere other than APP_DATA, you should have full write access anywhere.

Contrary to some other people's comments, if you store files in your site's local storage then your files are safe against the VM going down and are instantly available to all your other instances. This is because the files are not actually being stored on the local VM, it's just an illusion. (The only exception is if you store stuff in the %TEMP% folder. That stuff is actually saved on the VM and can vanish at any time).

That said, if you expect a lot of data I/O or need a lot of storage, blob storage is the best way to go.

Upvotes: 2

Alex Warren
Alex Warren

Reputation: 7547

You shouldn't be using App_Data to store uploaded files using Azure Web Sites. You only get a limited amount of space, and if you scale your site to more instances, the uploaded files will only be available on the instance where they were uploaded!

The correct way to handle uploaded files is indeed to use Blob storage. You can use this easily from your web site. Just install the Azure .NET Storage Client Library (this is available from Nuget).

There is a full tutorial on using the Azure .NET Storage Client Library at http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-blobs/

You can easily display uploaded images on your site by making the blob container public. Then you can link directly to an image within your blob container - it will have a URL like

https:// your storage account name .blob.core.windows.net/ your blob container name /filename.jpg

Upvotes: 3

Peter Lea
Peter Lea

Reputation: 1751

I would not look to build a solution that relies on local storage for azure websites or web services. You can't scale this solution and there's a chance that the VM may get re-imaged etc.

I would look at blob storage, I restrict uploads to less than 4mb as I validate them on the server before writing them into blob storage, but you can stream it direct into storage I believe.

Here's a Guide to uploading large files from MVC that may help get you started.

Upvotes: 1

Related Questions