[英]How to copy blobs between containers?
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");
}
If I have my page blobs inside folder(CloudBlobDirectory) in source container I don't want to copy folder I want to copy just my page blobs to target container. 如果我在源容器中的文件夹(CloudBlobDirectory)中有我的页面blob我不想复制文件夹我想将我的页面blob复制到目标容器。 How to do this?
这该怎么做?
You can use the TransferManager class included in the Azure Data Movement library. 您可以使用Azure数据移动库中包含的TransferManager类 。
You can copy each blob by executing: 您可以通过执行以下命令复制每个blob:
await TransferManager.CopyAsync(sourceBlob, targetBlob, isServiceCopy: false);
Note that if you choose to use service side copy ('isServiceCopy' set to true), Azure (currently) doesn't provide SLA for that. 请注意,如果您选择使用服务端副本('isServiceCopy'设置为true),则Azure(当前)不会为此提供SLA。 Setting 'isServiceCopy' to false will download the source blob locally and upload it to the target blob.
将'isServiceCopy'设置为false将在本地下载源blob并将其上载到目标blob。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.