I am using this code to copy blobs from one account to another... but it throws an exception.
var srcAccount = CloudStorageAccount.Parse("connection string 1");
var dstAccount = CloudStorageAccount.Parse("connection string 2");
var srcBlobClient = srcAccount.CreateCloudBlobClient();
var dstBlobClient = dstAccount.CreateCloudBlobClient();
foreach (var srcCloudBlobContainer in srcBlobClient.ListContainers())
{
var dstCloudBlobContainer = dstBlobClient
.GetContainerReference(srcCloudBlobContainer.Name);
dstCloudBlobContainer.CreateIfNotExists();
foreach (var srcBlob in srcCloudBlobContainer.ListBlobs())
{
if (srcBlob.GetType() == typeof(CloudBlockBlob))
{
var srcBlockBlock = (CloudBlockBlob)srcBlob;
var dstBlockBlock = dstCloudBlobContainer
.GetBlockBlobReference(srcBlockBlock.Name);
// throws exception StorageException:
// The remote server returned an error: (404) Not Found.
dstBlockBlock.StartCopyFromBlob(srcBlockBlock.Uri);
}
}
}
Microsoft states that cross account copy is supported, but I cannot get it to work.
What am I doing wrong?
Can you check the source blob container's ACL? If it's
Private
you may either need to change the ACL toPublic
/Blob
or create a SAS URL. You can use the following code if you wish to keep your blob container's ACL asPrivate
and make use of SAS URL: