[英]Copy blob from one directory into another in same container Azure Storage
我正在尝试从一个目录复制blob,然后将其复制到另一目录,然后从源中删除blob。 我已经尝试了下面的代码,但是没有完成复制并粘贴到另一个文件夹中,但是删除操作有效。
var cred = new StorageCredentials("storageName", "Key");
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("containerName");
CloudBlockBlob sourceBlob = container.GetBlockBlobReference("folder/test.jpg");
//this doesn't work
sourceBlob.StartCopyAsync(new Uri("destination url"));
//this works
sourceBlob.DeleteAsync();
您需要await
如Igor所述。
StartCopyAsync
只是“启动”复制过程的一种方法,您仍然需要在删除Blob之前监视复制状态。 请在这里找到我的答案以获取更多详细信息: 使用blob StartCopyAsync时如何获取azure blob的更新副本状态
好吧,您必须等待async
方法。 StartCopyAsync失败,因为您同时运行删除文件调用。 尝试使用await
或Result
属性。
var cred = new StorageCredentials("storageName", "Key");
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("containerName");
CloudBlockBlob sourceBlob = container.GetBlockBlobReference("folder/test.jpg");
//this doesn't work
await sourceBlob.StartCopyAsync(new Uri("destination url"));
//this works
await sourceBlob.DeleteAsync();
代码未经测试,但是应该给您一个总体思路。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.