存储Blob复制操作期间发生错误-在实体的当前状态下,不允许执行请求的操作

问题描述 投票:0回答:1

我具有以下将数据复制到目标存储Blob的方法

private static async Task MoveMatchingBlobsAsync(IEnumerable<ICloudBlob> sourceBlobRefs, 
           CloudBlobContainer sourceContainer, 
           CloudBlobContainer destContainer)
{
   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");
           }
          }
        }
      }

我正在接受例外处理,没有更多信息

实体的当前状态不允许所请求的操作

可能是什么原因?

这是我从来源位置收集Blob的方法

  private static async Task<IEnumerable<ICloudBlob>> FindMatchingBlobsAsync(CloudBlobContainer blobContainer,string prefix, int maxrecords,int total)
    {
        List<ICloudBlob> blobList = new List<ICloudBlob>();
        BlobContinuationToken token = null;
        do
        {
            BlobResultSegment segment = await blobContainer.ListBlobsSegmentedAsync(prefix: prefix, useFlatBlobListing: true, BlobListingDetails.None, maxrecords, token, new BlobRequestOptions(), new OperationContext());
            token = segment.ContinuationToken;
            foreach (var item in segment.Results)
            {
                blobList.Add((ICloudBlob)item);
                if (blobList.Count > total) // total record count is configured
                    token = null;
            }
        } while ( token != null);
        return blobList;
    }

这是我的GetSharedAccessUri方法,它没有任何问题地返回Uri

     private static string GetSharedAccessUri(string blobName, CloudBlobContainer container)
    {
        DateTime toDateTime = DateTime.Now.AddMinutes(60);

        SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy
        {
            Permissions = SharedAccessBlobPermissions.Read,
            SharedAccessStartTime = null,
            SharedAccessExpiryTime = new DateTimeOffset(toDateTime)
        };

        CloudBlockBlob blob = container.GetBlockBlobReference(blobName);
        string sas = blob.GetSharedAccessSignature(policy);

        return blob.Uri.AbsoluteUri + sas;
    }

附加问题:是否有任何GUI工具可将Blob数据复制到目标存储帐户?

c# azure azure-storage-blobs
1个回答
0
投票

您可以参考this post中的代码进行复印操作。如果本文中的解决方案对您没有帮助,请告诉我,我将继续跟进以帮助您解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.