azure - Create Shared Access Token with Microsoft.WindowsAzure.Storage returns 403 -


i have simple method uses new storage api create sas , copy blob 1 container another.

i trying use copy blob between storage accounts. have 2 storage accounts, exact same containers, , trying copy blob storage account's container storage account's container.

i don't know if sdk built that, seems common scenario.

some additional information:

  1. i create token on destination container. token need created on both source , destination? take time register token? need create each request, or once per token "lifetime"?

i should mention 403 unauthorized result http error code.

  private static string createsharedaccesstoken(cloudblobclient blobclient, string containername)     {         var container = blobclient.getcontainerreference(containername);         var blobpermissions = new blobcontainerpermissions();          // shared access policy provides read/write access container 10 hours:          blobpermissions.sharedaccesspolicies.add("solutionpolicy", new sharedaccessblobpolicy()         {             // ensure sas valid don’t set start time              // can avoid failures caused small clock differences:              sharedaccessexpirytime = datetime.utcnow.addhours(1),             permissions = sharedaccessblobpermissions.write |                           sharedaccessblobpermissions.read         });           blobpermissions.publicaccess = blobcontainerpublicaccesstype.blob;          container.setpermissions(blobpermissions);          return container.getsharedaccesssignature(new sharedaccessblobpolicy(), "solutionpolicy");      } 

down line use token call copy operation, returns 403:

  var uri = new uri(srcblob.uri.absoluteuri + blobtoken);             destblob.startcopyfromblob(uri); 

my version of azure.storage 2.1.0.2.

here full copy method in case helps:

    private static void copyblobs(         cloudblobcontainer srccontainer, string blobtoken,         cloudblobcontainer destcontainer)     {         var srcbloblist             = srccontainer.listblobs(string.empty, true, bloblistingdetails.all); // set none in prod (4perf)          //// sas token use blobs          //string token = srccontainer.getsharedaccesssignature(         //    new sharedaccessblobpolicy(), "solutionpolicy");          bool pendingcopy = true;          foreach (var src in srcbloblist)         {             var srcblob = src icloudblob;              // determine blobtype:              icloudblob destblob;             if (srcblob.properties.blobtype == blobtype.blockblob)             {                 destblob = destcontainer.getblockblobreference(srcblob.name);             }             else             {                 destblob = destcontainer.getpageblobreference(srcblob.name);             }              // determine copy state:              if (destblob.copystate != null)             {                 switch (destblob.copystate.status)                 {                     case copystatus.failed:                         log.info(destblob.copystate);                         break;                      case copystatus.aborted:                         log.info(destblob.copystate);                         pendingcopy = true;                         destblob.startcopyfromblob(destblob.copystate.source);                         return;                      case copystatus.pending:                         log.info(destblob.copystate);                         pendingcopy = true;                         break;                 }             }               // copy using policy id:             var uri = new uri(srcblob.uri.absoluteuri + blobtoken);             destblob.startcopyfromblob(uri);               //// copy using src blob sas             //var source = new uri(srcblob.uri.absoluteuri + token);             //destblob.startcopyfromblob(source);          }     } 

and account , client (vetted) code:

       var credentials = new storagecredentials("bar", "foo");         var account = new cloudstorageaccount(credentials, true);         var blobclient = account.createcloudblobclient();         var sastoken = createsharedaccesstoken(blobclient, "content"); 

when use rest client seems work... ideas?

consider problem:

var uri = new uri(srcblob.uri.absoluteuri + blobtoken); 

probably calling "tostring" method of uri produce "human redable" version of url. if blobtoken contain special caracters example "+" cause token malformed error on storage server refuse give access.

use instead:

string uri = srcblob.uri.absoluteuri + blobtoken; 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -