将一个 Azure blob 复制到 Azure Storage Client 2.0 中的另一个 blob [英] Copying one Azure blob to another blob in Azure Storage Client 2.0

查看:24
本文介绍了将一个 Azure blob 复制到 Azure Storage Client 2.0 中的另一个 blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在旧的 1.7 存储客户端中有一个 CloudBlob.CopyFromBlob(otherBlob) 方法,但它似乎没有出现在 2.0 版本中.复制 blob 的推荐最佳做法是什么?我确实看到了 iCloudBlob.BeginStartCopyFromBlob 方法.如果这是合适的方法,我该如何使用它?

In the old 1.7 storage client there was a CloudBlob.CopyFromBlob(otherBlob) method, but it does not seem to be present in the 2.0 version. What is the recommended best practice for copying blobs? I do see a ICloudBlob.BeginStartCopyFromBlob method. If that is the appropriate method, how do I use it?

推荐答案

Gaurav Mantri 写了一系列文章在 2.0 版的 Azure 存储上.我从他的博客文章 Storage Client Library 2.0 – 为 Blob Copy 迁移 Blob 存储代码

Gaurav Mantri has written a series of articles on Azure Storage on version 2.0. I have taken this code extract from his blog post of Storage Client Library 2.0 – Migrating Blob Storage Code for Blob Copy

CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer sourceContainer = cloudBlobClient.GetContainerReference(containerName);
CloudBlobContainer targetContainer = cloudBlobClient.GetContainerReference(targetContainerName);
string blobName = "<Blob Name e.g. myblob.txt>";
CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference(blobName);
CloudBlockBlob targetBlob = targetContainer.GetBlockBlobReference(blobName);
targetBlob.StartCopyFromBlob(sourceBlob);

这篇关于将一个 Azure blob 复制到 Azure Storage Client 2.0 中的另一个 blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆