我遇到了一个问题,我试图将CloudPageBlob复制到另一个Azure订阅中的存储帐户.出于某种原因,当我进行复制调用时,我一直收到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
.
拥有私有源容器是个问题.您需要获取一个共享访问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; }