Explore Courses Blog Tutorials Interview Questions
0 votes
in Azure by (45.3k points)

In the old 1.7 storage client, there was a CloudBlob. CopyFromBlob (otherBlob) method, but it does not seem to be present in the 2.0 version. What is the recommended best practice for copying blobs? I do see an ICloudBlob.BeginStartCopyFromBlob method. If that is the appropriate method, how do I use it?

1 Answer

0 votes
by (16.8k points)

Try this, it should work:

CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);

CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();

CloudBlobContainer sourceContainer = cloudBlobClient.GetContainerReference(containerName);

CloudBlobContainer targetContainer = cloudBlobClient.GetContainerReference(targetContainerName);

string blobName = "<Blob Name e.g. myblob.txt>";

CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference(blobName);

CloudBlockBlob targetBlob = targetContainer.GetBlockBlobReference(blobName);


Browse Categories