繁体   English   中英

将Blob从一个目录复制到同一容器Azure存储中的另一个目录

[英]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();

好吧,您必须等待async方法。 StartCopyAsync失败,因为您同时运行删除文件调用。 尝试使用awaitResult属性。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM