Azure存储将Blob移动到其他容器 [英] Azure Storage move blob to other container
本文介绍了Azure存储将Blob移动到其他容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种将Azure中的Blob从一个容器移动到另一个容器的方法.我发现的唯一解决方案是使用Azure存储数据移动库,但这似乎在不同帐户之间起作用.我想将同一个帐户中的Blob移到另一个容器中.
I'm looking for an approach to move a blob in Azure from one container to another. The only solution I found is to use the Azure Storage Data Movement Library, but this seems to work between different accounts. I would like to move the blob within the same account to an other container.
推荐答案
这是对我有用的(答案由@Deumber发布更好的答案后编辑):
Here is what worked for me (answer edited after better answer by @Deumber was posted):
public async Task<CloudBlockBlob> Move(CloudBlockBlob srcBlob, CloudBlobContainer destContainer)
{
CloudBlockBlob destBlob;
if (srcBlob == null)
{
throw new Exception("Source blob cannot be null.");
}
if (!destContainer.Exists())
{
throw new Exception("Destination container does not exist.");
}
//Copy source blob to destination container
string name = srcBlob.Uri.Segments.Last();
destBlob = destContainer.GetBlockBlobReference(name);
await destBlob.StartCopyAsync(srcBlob);
//remove source blob after copy is done.
srcBlob.Delete();
return destBlob;
}
这篇关于Azure存储将Blob移动到其他容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文