Upload to Azure Blob from Xamarin.Forms PCL -


i'm trying upload image's stream azure blob xamarin.forms pcl app using windowsazure.storage 7.0.2-preview. reason, storagecredentials doesn't recognize accountname of sas token.

var credentials = new storagecredentials("https://<account-name>.blob.core.windows.net/..."); cloudstorageaccount account = new cloudstorageaccount(credentials, true); 

and uploading this:

 public async task<string> writefile(string containername, string filename, system.io.stream stream, string contenttype = "")     {         var container = getblobclient().getcontainerreference(containername);         var filebase = container.getblockblobreference(filename);         await filebase.uploadfromstreamasync(stream);         if (!string.isnullorempty(contenttype))         {             filebase.properties.contenttype = contenttype;             await filebase.setpropertiesasync();         }         return filebase.uri.tostring();     } 

how can resolve problem? there better solution of uploading azure storage? thank you!

the storagecredentials constructor takes in sas token expects query part of sas token, not full uri string. if have full uri resource, including sas token, common thing use constructor object directly. example, if have uri:

string mybloburi = @"https://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sv=2015-04-05&st=2015-04-29t22%3a18%3a26z&se=2015-04-30t02%3a23%3a26z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=z%2frhix5xcg0mq2rqi3olwtjeg2tykboxr1p9zuxdtkk%3d"; 

you can create blob object such:

cloudblockblob filebase = new cloudblockblob(new uri(mybloburi)); 

if want use storagecredentials , cloudstorageaccount classes reason (maybe have accountsas, example), here 1 way make work:

string sastoken = @"sv=2015-04-05&st=2015-04-29t22%3a18%3a26z&se=2015-04-30t02%3a23%3a26z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=z%2frhix5xcg0mq2rqi3olwtjeg2tykboxr1p9zuxdtkk%3d"; storagecredentials credentials = new storagecredentials(sastoken); cloudstorageaccount account = new cloudstorageaccount(credentials, "myaccount", "core.windows.net", true) 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo