I am creating a console app that copies all blobs in all containers from an account we use for production to another we use for development. I have the following method to d
Because the source blob container ACL is Private
, what you would need to do is create a SAS Token (either on the blob container or on individual blobs in that container) with Read
permission and append this SAS token to your blob's URL. Please see modified code below:
static void CopyBlobsToDevelopment()
{
// Get a list of containers in production
List productionBlobContainers = productionStorage.GetContainerList();
// For each container in production...
foreach (var productionContainer in productionBlobContainers)
{
//Gaurav --> create a SAS on source blob container with "read" permission. We will just append this SAS
var sasToken = productionContainer.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessExpiryTime = DateTime.UtcNow.AddDays(1),
});
// Get a list of blobs in the production container
var blobList = productionStorage.GetBlobList(productionContainer.Name);
// Need a referencee to the development container
var developmentContainer = developmentStorage.GetContainer(productionContainer.Name);
// For each blob in the production container...
foreach (var blob in blobList)
{
CloudBlockBlob targetBlob = developmentContainer.GetBlockBlobReference(blob.Name);
targetBlob.StartCopyFromBlob(new Uri(blob.Uri.AbsoluteUri + sasToken));
}
}
}
I haven't tried running this code so please excuse me if you run into any errors with this code. But hopefully you get the idea.