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?
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).
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.
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.
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);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With