我试图将一个blob,特别是vhd,从存储帐户复制到另一个存储帐户。我写的应用程序拥有两个存储帐户的所有者访问权限,可以在这些存储帐户上运行其他操作。 vhd上没有租约(没有附加VM)。我有以下代码但得到403禁止响应。
StorageCredentials scSource = new StorageCredentials(SourceStorageName, strSourceStorageKey);
StorageCredentials scTarget = new StorageCredentials(TargetStorageName, strTargetStorageKey);
CloudStorageAccount csaSource = new CloudStorageAccount(scSource, true);
CloudStorageAccount csaTarget = new CloudStorageAccount(scTarget, true);
CloudBlobClient cbcSource = csaSource.CreateCloudBlobClient();
CloudBlobClient cbcTarget = csaTarget.CreateCloudBlobClient();
CloudBlobContainer bcSource = cbcSource.GetContainerReference(SourceContainer);
CloudBlobContainer bcTarget = cbcTarget.GetContainerReference(TargetContainer);
CloudBlob cbSource = bcSource.GetBlobReference(strSourceDiskName);
CloudBlob cbTarget = bcTarget.GetBlobReference(strTargetDiskName);
Task<string> tskCopy = cbTarget.StartCopyAsync(cbSource.Uri);
while (tskCopy.Status != TaskStatus.RanToCompletion)
{
if (tskCopy.Exception != null)
throw tskCopy.Exception;
Thread.Sleep(2500);
}
不确定为什么会发生这种情况,因为我可以通过其他工具(云莓等)将blob从一个存储帐户复制到另一个存储帐户。
答案 0 :(得分:1)
感谢Gaurav Mantri指出我正确的方向。在查找共享访问签名后,我发现了Microsoft https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-shared-access-signature-part-2/
中的这篇文章此代码具体:
SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
sasConstraints.SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-5);
sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24);
sasConstraints.Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write;
// Generate the shared access signature on the blob, setting the constraints directly on the signature.
string sasBlobToken = blob.GetSharedAccessSignature(sasConstraints);
// Return the URI string for the container, including the SAS token.
return blob.Uri + sasBlobToken;
答案 1 :(得分:-1)
您是否可以检查Blob是否仍在Azure门户中注册为虚拟磁盘?如果是这样,请删除磁盘引用但保留关联的VHD,以便释放该blob的租约。
如果您不想删除Azure门户中的虚拟磁盘引用,则可以为关联的Blob创建Blob快照,并在复制blob时将快照输入为Blob源。