我遇到一种情况,有时CloudBlockBlob.StartCopyAsync
仅将0字节的数据写入输入资产的斑点...应该是什么情况?因此,我决定在不增加块Blob长度的情况下开始复制...有什么建议吗?
private async Task CreateInputAssetBlobAsync(UploadRequest request)
{
var cloudBlobContainer = new CloudBlobContainer(request.InputAssetStorageUri);
var blockBlob = cloudBlobContainer.GetBlockBlobReference(request.BlobName);
var storageCredentials = new Microsoft.Azure.Storage.Auth.StorageCredentials(_apiAccess.TempBlobAccountName, _apiAccess.TempBlobContainerKey);
var tempBlobContainer = new CloudBlobContainer(new Uri(_apiAccess.TempBlobContainerAddress), storageCredentials);
var tempBlockBlob = tempBlobContainer.GetBlockBlobReference(request.BlobName);
try
{
await blockBlob.StartCopyAsync(tempBlockBlob);
do
{
if (blockBlob.CopyState.Status == CopyStatus.Pending)
await Task.Delay(1000);
await blockBlob.FetchAttributesAsync();
}
while (blockBlob.CopyState.Status != CopyStatus.Success);
return;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
答案 0 :(得分:0)
要复制Blob内容,应使用以下代码。
有关更多详细信息,您可以download my sample in github(BlobContainerCopy)。它有效,我认为对您有用。
您也可以参考这篇文章。希望我在这篇文章中的回答也能对您有所帮助。
foreach (ICloudBlob sourceBlobRef in sourceBlobRefs)
{
if (sourceBlobRef.Properties.ContentType != null)
{
// Copy the source blob
CloudBlockBlob destBlob = destContainer.GetBlockBlobReference(sourceBlobRef.Name);
try
{
//exception throwed here - StartCopyAsync
await destBlob.StartCopyAsync(new Uri(GetSharedAccessUri(sourceBlobRef.Name, sourceContainer)));
ICloudBlob destBlobRef = await destContainer.GetBlobReferenceFromServerAsync(sourceBlobRef.Name);
while (destBlobRef.CopyState.Status == CopyStatus.Pending)
{
Console.WriteLine($"Blob: {destBlobRef.Name}, Copied: {destBlobRef.CopyState.BytesCopied ?? 0} of {destBlobRef.CopyState.TotalBytes ?? 0}");
await Task.Delay(500);
destBlobRef = await destContainer.GetBlobReferenceFromServerAsync(sourceBlobRef.Name);
}
Console.WriteLine($"Blob: {destBlob.Name} Complete");
}
catch (Exception e)
{
Console.WriteLine($"Blob: {destBlob.Name} Copy Failed");
}
}
}