2017-01-10 50 views
2

我遇到了一個問題,我試圖將CloudPageBlob複製到不同Azure訂閱中的存儲帳戶。出於某種原因,當我撥打電話,以複製,我一直得到一個404錯誤:CloudPageBlob StartCopyAsync失敗,狀態爲404

CloudBlobContainer destContainer; 
CloudBlob sourceBlob; 
string destBlobName; 

var sourcePageBlob = sourceBlob as CloudPageBlob; 
if (sourcePageBlob != null) 
{ 
    var destBlob = destContainer.GetPageBlobReference(destBlobName); 
    await destBlob.StartCopyAsync(sourcePageBlob, AccessCondition.GenerateIfExistsCondition(), AccessCondition.GenerateEmptyCondition(), new BlobRequestOptions(), new OperationContext()); 
    return destBlob; 
} 

調用返回{"The remote server returned an error: (404) Not Found."} 但是,如果我把它sourcePageBlob.Exists()返回true

+0

你destConConiner是否存在? 404錯誤可能是由於此。此外,由於您指定了AccessCondition.GenerateIfExistsCondition(),我認爲destBlob也需要存在。爲什麼不刪除此訪問條件? –

+0

您可以檢查源容器ACL嗎?它是'私人'嗎? –

+0

是的,源容器是私人的。應該這樣嗎?我有一個訪問鍵,並能夠在源容器上執行操作。 –

回答

6

擁有私有源容器是個問題。您需要獲得允許目標存儲帳戶訪問源共享訪問URI的共享訪問URI。這篇博文解釋它:https://alexandrebrisebois.wordpress.com/2013/06/25/copy-blobs-with-startcopyfromblob-and-track-its-progression-using-copystate/

CloudBlobContainer destContainer; 
CloudBlob sourceBlob; 
string destBlobName; 

var sharedAccessUri = GetShareAccessUri(sourceBlob); 
var sourcePageBlob = sourceBlob as CloudPageBlob; 
if (sourcePageBlob != null) 
{ 
    var destBlob = destContainer.GetPageBlobReference(destBlobName); 
    await destBlob.StartCopyAsync(new Uri(sharedAccessUri)); 
    return destBlob; 
} 

private string GetShareAccessUri(CloudBlob sourceBlob) 
{ 
    int validMins = 300; 
    var policy = new SharedAccessBlobPolicy 
    { 
    Permissions = SharedAccessBlobPermissions.Read, 
    SharedAccessStartTime = null, 
    SharedAccessExpiryTime = DateTimeOffset.Now.AddMinutes(validMins) 
    }; 

    var sas = sourceBlob.GetSharedAccessSignature(policy); 
    return sourceBlob.Uri.AbsoluteUri + sas; 
} 
相關問題