簡體   English   中英

將Blob從一個目錄復制到同一容器Azure存儲中的另一個目錄

[英]Copy blob from one directory into another in same container Azure Storage

問題

我正在嘗試從一個目錄復制blob,然后將其復制到另一目錄,然后從源中刪除blob。 我已經嘗試了下面的代碼,但是沒有完成復制並粘貼到另一個文件夾中,但是刪除操作有效。

var cred = new StorageCredentials("storageName", "Key");
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("containerName");
CloudBlockBlob sourceBlob = container.GetBlockBlobReference("folder/test.jpg");

//this doesn't work
sourceBlob.StartCopyAsync(new Uri("destination url"));
//this works
sourceBlob.DeleteAsync();

好吧,您必須等待async方法。 StartCopyAsync失敗,因為您同時運行刪除文件調用。 嘗試使用awaitResult屬性。

var cred = new StorageCredentials("storageName", "Key");
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("containerName");
CloudBlockBlob sourceBlob = container.GetBlockBlobReference("folder/test.jpg");

//this doesn't work
await sourceBlob.StartCopyAsync(new Uri("destination url"));
//this works
await sourceBlob.DeleteAsync();

代碼未經測試,但是應該給您一個總體思路。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM