gpt4 book ai didi

c# - 如果目标中存在 Blob,如何覆盖 Blob

转载 作者:太空宇宙 更新时间:2023-11-03 22:39:09 26 4
gpt4 key购买 nike

我正在使用 TransferManager 将 blob 从一个容器复制到另一个容器。

CloudStorageAccount sourceStorageAccount = CloudStorageAccount.Parse(@"source storage account connection string");
CloudStorageAccount destStorageAccount = CloudStorageAccount.Parse(@"destination storage account connection string");

CloudBlobClient sourceBlobClient = sourceStorageAccount.CreateCloudBlobClient();
CloudBlobClient destBlobClient = destStorageAccount.CreateCloudBlobClient();
var sourceContainer = sourceBlobClient.GetContainerReference("sourceContainer");
var destContainer = destBlobClient.GetContainerReference("destContainer");

CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference("copy.txt");
CloudBlockBlob targetBlob = destContainer.GetBlockBlobReference("copy.txt");

TransferManager.CopyAsync(sourceBlob, targetBlob, true).Wait();

但是当文件存在于目标中时,它会抛出错误说明

"Skiped file \"https://sourceabcd.blob.core.windows.net/sourcecontainer/test1.txt\" because target \"https://sourceabcd.blob.core.windows.net/destcontainer/test1.txt\" already exists."} System.Exception {Microsoft.WindowsAzure.Storage.DataMovement.TransferSkippedException

如果目标中存在该文件,是否可以选择覆盖该文件?

最佳答案

您可能会从 here 得到异常

我认为你可以做如下所示

TransferContext transferContext = new SingleTransferContext();
transferContext.ShouldOverwriteCallbackAsync = TransferContext.ForceOverwrite;
TransferManager.CopyAsync(sourceBlob, targetBlob, true,null,transferContext).Wait();

我对此不太了解,但我在 github 上找到了一些测试用例 here

关于c# - 如果目标中存在 Blob,如何覆盖 Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53320785/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com