I need to create a library that will allow me to upload blob data to certain Azure account. The following parameters will be provided dynamically, by external webservice:
x-ms-date, x-ms-version, Content-MD5, x-ms-blob-type, Content-Type, Authorization
According to examples here:
I should be able to upload the blob data by only URL and SasToken with something like:
Uri blobUri = new Uri("http://127.0.0.1:10000/devstoreaccount1/sascontainer/myblob.txt");
// Create credentials with the SAS token. The SAS token was created in previous example.
StorageCredentials credentials = new StorageCredentials(sasToken);
// Create a new blob.
CloudBlockBlob blob = new CloudBlockBlob(blobUri, credentials);
// Upload the blob.
// If the blob does not yet exist, it will be created.
// If the blob does exist, its existing content will be overwritten.
using (var fileStream = System.IO.File.OpenRead(@"c:\Temp\myblob.txt"))
{
blob.UploadFromStream(fileStream);
}
However, the above assume that sasToken looks similar to this:
?sv=2015-07-08&sr=c&si=mypolicy&sig=FQctgR3waFrWpblkNJf6HYXAVa0%2BkxFUbP8Fr2op%2F%2FI%3D
While my serwice will only be provided with this:
{
"Key": "Authorization",
"Value": "SharedKey storageAccountName:Tz7EqAl6OszIxGjBUk2qcxs82Af4Xq9CxyFx6u34LEI="
}
I have found some examples here:
https://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
On how to do this with REST API:
Request Syntax:
PUT https://myaccount.blob.core.windows.net/mycontainer/myblockblob HTTP/1.1
Request Headers:
x-ms-version: 2015-02-21
x-ms-date: <date>
Content-Type: text/plain; charset=UTF-8
x-ms-blob-content-disposition: attachment; filename="fname.ext"
x-ms-blob-type: BlockBlob
x-ms-meta-m1: v1
x-ms-meta-m2: v2
Authorization: SharedKey myaccount:YhuFJjN4fAR8/AmBrqBz7MG2uFinQ4rkh4dscbj598g=
Content-Length: 11
Request Body:
hello world
But since I'm new to Azure, I can't figure out how to do the above with storage client... Do I have to somehow manually "map" provided header parameters to query string parameters or is there a better/other way? Or perhaps this is not supported by Storage Client, and I should use REST approach?
EDIT1:
To be clear: I - more or less - know, how to upload the blob with sas token, as long as it has this form:
Problem is - this token will NOT be provided - instead, the website we are trying to integrate with, will publish a webservice, and this webservice (which we have no control over) will provide the following five parameters (example data below):
{
"Key": "x-ms-date",
"Value": "Mon, 13 Jun 2016 10:22:05 GMT"
},
{
"Key": "x-ms-version",
"Value": "2015-04-05"
},
{
"Key": "Content-MD5",
"Value": "dnF5x6K/8ZZRzpfSlMMM+w=="
},
{
"Key": "x-ms-blob-type",
"Value": "BlockBlob"
},
{
"Key": "Content-Type",
"Value": "application/octet-stream"
},
{
"Key": "Authorization",
"Value": "SharedKey taxdocumentstorage09tst:sImBLJPWACNPzi94eJEDRU4Bt5hz9sPURjwy46KixmM="
}