Upload files to Azure Blob Storage with using Shared Access Keys

I had a task of uploading files from command line client to a private container in Azure Blob Storage. And as part of the overall infrastructure I also has MVC4 and WebApi sites running on my Azure Web-Site installation.

The problem with uploading files was that the container was private. Before, every time I used the container, I used private key to access it, but all the operations were contained on the server: user submits a file in a form in a browser, file is passed through MVC web-site, where it is uploaded into Azure blob storage. And in MVC there is a very easy way to manage multiple uploaded files.

Now my task was similar, but as a client I had command line application and server side was WebApi. In WebApi it is not so easy to manage uploaded files, especially if you had multiple files for upload. You could not (or I could not find a way to do that) simply redirect the upload stream from controller into Azure Blob. You had to store file somewhere and then copy that to Azure storage. And there are a few problems with that:

Continue reading

Capture Azure exception message

I’m fighting with Azure and publishing via PowerShell at the moment.
It seems that powershell is problematic and does not want to play. Especially with slow deployment times – you need to wait for it to throw errors, and that usually takes 3-15 minutes depending on your internet speed.

So you would want to get error message captured:

# try publish - here I get 500 server error
New-AzureDeployment -Slot Staging -Package $package -Configuration $configuration -ServiceName $service

# capture error stream
$sr = new-object System.IO.StreamReader($Error[0].Exception.InnerException.Response.GetResponseStream())  
$txt = $sr.ReadToEnd() 

# print out the message
$txt

Hopefully this will help a bit.
Info taken from this guy