【问题标题】:Azure Blob - ASP.NET, Copy Blob to within Same CollectionAzure Blob - ASP.NET,将 Blob 复制到同一集合中
【发布时间】:2020-11-03 08:33:42
【问题描述】:

我正在尝试从现有的 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);

【问题讨论】:

标签: c# azure file copy blob


【解决方案1】:

我在我的网站上进行了测试,效果很好。

您可以参考以下代码:

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);

【讨论】:

    猜你喜欢
    • 2014-04-13
    • 2016-02-12
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 2021-12-31
    • 2013-12-08
    • 2019-04-04
    • 1970-01-01
    相关资源
    最近更新 更多