Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying one Azure blob to another blob in Azure Storage Client 2.0

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 a ICloudBlob.BeginStartCopyFromBlob method. If that is the appropriate method, how do I use it?

like image 745
Craig Smitham Avatar asked Jan 04 '13 06:01

Craig Smitham


People also ask

How do I copy files from Azure Blob storage to another blob storage?

Copy a blob to another storage account by using the azcopy copy command. This example encloses path arguments with single quotes (''). Use single quotes in all command shells except for the Windows Command Shell (cmd.exe).

How do I transfer files from one Azure storage to another?

Copy and move blobs from one container or storage account to another from the command line and in code. Use . NET, AzCopy, and Azure CLI to migrate files between Azure storage accounts.

What is the difference between blob and Adls gen2?

Key DifferencesBlob: General purpose object store for a wide variety of storage scenarios, including big data analytics. ADLS: Optimized storage for big data analytics workloads. Blob: Good storage retrieval performance. ADLS: Better storage retrieval performance.


2 Answers

Gaurav Mantri has written a series of articles on Azure Storage on version 2.0. I have taken this code extract from his blog post of Storage Client Library 2.0 – Migrating Blob Storage Code for Blob Copy

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); targetBlob.StartCopyFromBlob(sourceBlob); 
like image 139
Naveen Vijay Avatar answered Sep 28 '22 00:09

Naveen Vijay


Using Storage 6.3 (much newer library than in original question) and async methods use StartCopyAsync (MSDN)

  CloudStorageAccount storageAccount = CloudStorageAccount.Parse("Your Connection");    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();   CloudBlobContainer container = blobClient.GetContainerReference("YourContainer");    CloudBlockBlob source = container.GetBlockBlobReference("Your Blob");   CloudBlockBlob target = container.GetBlockBlobReference("Your New Blob");            await target.StartCopyAsync(source); 
like image 30
Aaron Sherman Avatar answered Sep 28 '22 01:09

Aaron Sherman