Azure Storage move blob to other container

前端 未结 3 943
鱼传尺愫
鱼传尺愫 2021-02-12 11:50

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 t

3条回答
  •  死守一世寂寞
    2021-02-12 12:47

    The answer accepted in this question will move the file to your server memory and then upload it from your memory to azure again.

    A better practice could be let all the work on Azure

    CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient();
        CloudBlobContainer sourceContainer = blobClient.GetContainerReference(SourceContainer);
        CloudBlobContainer targetContainer = blobClient.GetContainerReference(TargetContainer);
            
        CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference(fileToMove);
        CloudBlockBlob targetBlob = targetContainer.GetBlockBlobReference(newFileName);
                        await targetBlob.StartCopyAsync(sourceBlob);
    

提交回复
热议问题