[英]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();
您需要await
如Igor所述。
StartCopyAsync
只是“啟動”復制過程的一種方法,您仍然需要在刪除Blob之前監視復制狀態。 請在這里找到我的答案以獲取更多詳細信息: 使用blob StartCopyAsync時如何獲取azure blob的更新副本狀態
好吧,您必須等待async
方法。 StartCopyAsync失敗,因為您同時運行刪除文件調用。 嘗試使用await
或Result
屬性。
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.