In this part we will be looking into how we can use the Azure Storage REST API’s massive documentation in helping us uploading in our PRIVATE container. So after setting CORS on our container, now we need to give access to write or list what is in the container. For that we need a Shared Access Signature (SAS) in this signature when can specify the permission (Read, Write, List,…) as well as the expiration (how much time is the link SAS valid).

Luckily for us the SDK provides us a way of easily generating a SAS, but if you are like me and want to know/understand how that key is generated you will find in-depth explanation here.  With the SDK generating a list is as easy as the code below:

// Can write in the blob container testcors for the next 15 minutes 
var storageCredentials = new StorageCredentials(AccountName, Key); 
var account = new CloudStorageAccount(storageCredentials, false); 
var container = account.CreateCloudBlobClient().GetContainerReference("testcors"); // dont't forget CORS 
var sasWrite = container.GetSharedAccessSignature(new SharedAccessBlobPolicy() 
        Permissions = SharedAccessBlobPermissions.Write,     
        SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(15) 

After this code executes the value for my sasWrite will be something like :



That was the easy part, now you have to upload and make sure that EVERYTHING is perfect otherwise you will get sometimes helpful messages. In order to make everything work the way you want (eans uploading in your container without a hitch) make sure that:

  • SAS is valid
  • your URL is pointing to a new or existing(if you are splitting the upload…. PART II) blob in the container
  • the query string has these two other params :

&comp=block&blockid= [somethin base64]

blockid must be a valid Base64 string value that identifies the block. more info

          If we break it down we get:

          • https://democors.blob.core.windows.net is my storage account
          • /testcors/ is my PRIVATE container
          • 13a5e942-54a1-43ed-8cd1-dc753c92a311 is the filename in the container (I chose to store it using a GUID)
          • ?sv=2013-08-15&sr=c&sig=hfixkzR1GhwEc2xOnm5JpyKfCsHWHk6J6cFe81BoVSc%3D&se=2014-06-23T19%3A38%3A27Z&sp=w is the SAS
          • comp=block&blockid=MDAwMDAw the other part in order to PUT a list with a unique and valid blockid

          Once all the part of the file are uploaded you must finalize the operation by PUTting the list of blocks  in the proper order (that means that they could have been uploaded in any order as long as you know the proper order).

          So my request where I PUT the the XML message I would be putting would be :

          PUT https://democors.blob.core.windows.net/testcors/13a5e942-54a1-43ed-8cd1-dc753c92a311?sv=2013-08-15&sr=c&sig=hfixkzR1GhwEc2xOnm5JpyKfCsHWHk6J6cFe81BoVSc%3D&se=2014-06-23T19%3A38%3A27Z&sp=w&comp=blocklist

          <?xml version="1.0" encoding="utf-8"?>


          If everything is OK with my upload I will then get a 201 Created response.

          I will be blogging more on that subject since there is a lot possibilities to this subject.

          Enjoy !!!