在旧的1.7存储客户端中,有一个CloudBlob.CopyFromBlob(otherBlob)方法,但在2.0版本中似乎不存在。建议的最佳做法是复制Blob?我确实看到了ICloudBlob.BeginStartCopyFromBlob方法。如果那是合适的方法,该如何使用?
最佳答案
Gaurav Mantri在版本2.0的Azure存储上写了一系列文章。我已从他的Storage Client Library 2.0 – Migrating Blob Storage Code博客文章中摘录了此代码,以进行Blob复制
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);