Azure Blob-ASP.NET,将Blob复制到同一集合中



我正在尝试从现有的Azure blob复制到具有相同文件名的新位置。这两个文件夹在同一个容器中。有什么想法吗?

// details of where we want to copy from
var sourceContainerName = blobContainer.ToString();
string fileName = Path.GetFileName(@dirItem.Uri.ToString());
var sourceFilePath = "192-168-2-44/img/" + fileName;
// details of where we want to copy to
var destContainerName = blobContainer.ToString();
var destFilePath = "192-168-2-44/archive/" + fileName;
var sourceContainer = blobClient.GetContainerReference(sourceContainerName);
var destContainer = blobClient.GetContainerReference(destContainerName);
Console.WriteLine(sourceContainer);
Console.WriteLine(destContainer);
CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference(sourceFilePath);
CloudBlockBlob destBlob = destContainer.GetBlockBlobReference(destFilePath);
await destBlob.StartCopyAsync(sourceBlob);

我在我的站点中进行了测试,它运行得很好。

您可以参考以下代码:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse("connectionstring");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
var sourceContainer = blobClient.GetContainerReference("container");
var destContainer = blobClient.GetContainerReference("container");
var sourceFilePath = "hhh/www/" + "hello.txt";
var destFilePath = "hhh/jjj/" + "hello.txt";
CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference(sourceFilePath);
CloudBlockBlob destBlob = destContainer.GetBlockBlobReference(destFilePath);
await destBlob.StartCopyAsync(sourceBlob);

最新更新