Rune Hansen
Rune Hansen

Reputation: 1024

How To upload a Photo To Azure Blob with SAS from a WP App?

I am able to upload photos to blob with SAS from an Azure MVC web role with the code below:

using (var WS = new HLServiceClient())
{    
     /* Getting a SAS Write URI */
     var sasUri = WS.GetSasUriForBlobWrite(HLServiceReference.BusinessLogicMediaUsage.News, fileName);
     var writeBlob = new CloudBlob(sasUri);
     writeBlob.UploadFromStream(fileData.InputStream);
}

I would like to do the same thing from a WP app. But I can't figure out how to do it. I DON'T HAVE A LOT OF PROGRAMMING SKILL.

Can you tell me how to upload a photo to blob from a WP app with SAS?

There is a Windows Azure Storage Client Library for Windows Phone available on NuGet: Phone.Storage, it says "Class library for Windows Phone to communicate with Windows Azure storage services directly", I was hoping to find a simple solution using that: http://www.nuget.org/packages/Phone.Storage

I found a video tutorial on the Phone.Storage NuGet: http://channel9.msdn.com/posts/Using-the-Windows-Phone-Storage-NuGets-for-Windows-Azure

There is also a sample application demonstrating the usage of the Phone.Storage NuGet. http://www.nuget.org/packages/Phone.Storage.Sample

Still, though, it evades me if I can implement this in my application scenario?

Upvotes: 0

Views: 730

Answers (1)

Ming Xu - MSFT
Ming Xu - MSFT

Reputation: 2116

First, you need to generate the SAS from a hosted service. You can use the CloudBlob.GetSharedAccessSignature method (refer to http://msdn.microsoft.com/en-us/library/windowsazure/ee772922.aspx for a sample).

On the Windows Phone side, for small files, you simply need to issue an HTTP request to the SAS URL. You can use HttpWebRequest to do that. Try to search the web, and you can find a lot of samples, such as http://blogs.msdn.com/b/devfish/archive/2011/04/07/httpwebrequest-fundamentals-windows-phone-services-consumption-part-2.aspx.

For large files (larget than 64 MB), you need to divide them into smaller pieces, upload each piece as a block, and then commit the blob list (PUT block list: http://msdn.microsoft.com/en-us/library/windowsazure/dd179467). This is a tedious but not difficult task. You need to create quite a few HTTP requests.

The Windows Azure Toolkit for Windows Phone may also help: http://watwp.codeplex.com/. It contains a library that is similar to the Windows Azure library for .NET.

Upvotes: 1

Related Questions