gpt4 book ai didi

c# - 如何在容器之间复制 blob?

转载 作者:太空狗 更新时间:2023-10-30 01:32:14 25 4
gpt4 key购买 nike

public void CopyBlobsBetweenContainers(string sourceContainerName, string targetContainerName, IEnumerable<string> blobsToCopy)
{
foreach (var sourceBlobName in blobsToCopy)
{
_cancellationToken.ThrowIfCancellationRequested();

var sourceBlob = sourceContainer.GetPageBlobReference(sourceBlobName);
if (!sourceBlob.Exists())
{
throw new InvalidOperationException(SafeFormatter.Format(CloudLocalization.Culture, CloudLocalization.CannotCopyBlobDoesNotExist, sourceBlobName));
}

var targetBlob = targetContainer.GetPageBlobReference(sourceBlobName);
if (targetBlob.Exists())
{
throw new InvalidOperationException(SafeFormatter.Format(CloudLocalization.Culture, CloudLocalization.CannotCopyTargetAlreadyExists, sourceBlobName));
}

_logger.Debug("Copying blob '{0}' from container '{1}' to '{2}'", sourceBlobName, sourceContainerName, targetContainerName);

targetBlob.Create(sourceBlob.Properties.Length);
targetBlob.StartCopy(sourceBlob);
}

_logger.Debug("Copy blobs finished");
}

如果我的页面 blob 位于源容器中的文件夹(CloudBlobDirectory)内我不想复制文件夹,我只想将页面 blob 复制到目标容器。如何做到这一点?

最佳答案

您可以使用TransferManager class包含在Azure Data Movement中图书馆。

您可以通过执行以下命令来复制每个 blob:

await TransferManager.CopyAsync(sourceBlob, targetBlob, isServiceCopy: false);

请注意,如果您选择使用服务端复制(“isServiceCopy”设置为 true),Azure(当前)不会为此提供 SLA。将“isServiceCopy”设置为 false 会将源 blob 下载到本地并将其上传到目标 blob。

关于c# - 如何在容器之间复制 blob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37684700/

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