存储Blob复制操作期间出错-实体的当前状态不允许所请求的操作 [英] Error during storage blob copy operation - The requested operation is not allowed in the current state of the entity

查看:61
本文介绍了存储Blob复制操作期间出错-实体的当前状态不允许所请求的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下方法将数据复制到目标存储Blob

 私有静态异步任务MoveMatchingBlobsAsync(IEnumerable< ICloudBlob> sourceBlobRefs,CloudBlobContainer sourceContainer,CloudBlobContainer destContainer){foreach(sourceBlobRefs中的ICloudBlob sourceBlobRef){如果(sourceBlobRef.Properties.ContentType!= null){//复制源BlobCloudBlockBlob destBlob = destContainer.GetBlockBlobReference(sourceBlobRef.Name);尝试{//这里抛出异常-StartCopyAsync等待destBlob.StartCopyAsync(new Uri(GetSharedAccessUri(sourceBlobRef.Name,sourceContainer)));/ICloudBlob destBlobRef =等待destContainer.GetBlobReferenceFromServerAsync(sourceBlobRef.Name);而(destBlobRef.CopyState.Status == CopyStatus.Pending){Console.WriteLine($"Blob:{destBlobRef.Name},已复制:{destBlobRef.CopyState.TotalBytes 0}的{destBlobRef.CopyState.BytesCopied ?? 0}");等待Task.Delay(500);destBlobRef =等待destContainer.GetBlobReferenceFromServerAsync(sourceBlobRef.Name);}Console.WriteLine($"Blob:{destBlob.Name}完成");}捕获(异常e){Console.WriteLine($"Blob:{destBlob.Name}复制失败");}}}} 

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

在实体的当前状态下不允许执行请求的操作

可能是什么原因?

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

 私有静态异步Task< IEnumerable< ICloudBlob>>FindMatchingBlobsAsync(CloudBlobContainer blobContainer,字符串前缀,int maxrecords,in total){列表< ICloudBlob>blobList = new List< ICloudBlob>();BlobContinuationToken令牌= null;做{BlobResultSegment segment =等待blobContainer.ListBlobsSegmentedAsync(prefix:prefix,useFlatBlobListing:true,BlobListingDetails.None,maxrecords,token,new BlobRequestOptions(),new OperationContext());令牌= segment.ContinuationToken;foreach(segment.Results中的可变项){blobList.Add((ICloudBlob)item);if(blobList.Count> total)//配置总记录数令牌= null;}} while(token!= null);返回blobList;} 

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

 私有静态字符串GetSharedAccessUri(字符串blobName,CloudBlobContainer容器){DateTime toDateTime = DateTime.Now.AddMinutes(60);SharedAccessBlobPolicy策略=新的SharedAccessBlobPolicy{权限= SharedAccessBlobPermissions.Read,SharedAccessStartTime = null,SharedAccessExpiryTime =新的DateTimeOffset(toDateTime)};CloudBlockBlob blob = container.GetBlockBlobReference(blobName);字符串sas = blob.GetSharedAccessSignature(policy);返回blob.Uri.AbsoluteUri + sas;} 

这将仅迭代2个级别,但不会动态迭代直到内部级别.我在下面的层次结构中有斑点

 -容器-文件夹A-文件夹AA-文件夹AA1--File1.txt--File2.txt-文件夹AA2--File1.txt--File2.txt-文件夹AA3-文件夹AB--File8.txt-文件夹AC--File9.txt 

此层次结构是动态的

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

解决方案

更新

根据您的描述,我在官方示例代码中对其进行了修改.完全可以将一个容器中的数据复制到另一个帐户,并且代码已上传到Github.

要使用此示例代码,您需要修改 App.Config 文件.需要完善对生产环境的正式使用.

重要

您可以参考

I am having below method to copy data to destination storage 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");
           }
          }
        }
      }

I am getting below exception, there is no more information

The requested operation is not allowed in the current state of the entity

What may be the cause?

Here is my method to collect blob from the source location

  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;
    }

Here is my GetSharedAccessUri method which returns Uri without any issue

     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;
    }

This will iterate only 2 levels but not dynamically till the inner levels. I have blob in below hierarchy

  --Container
    --FolderA
      --FolderAA
        --FolderAA1
          --File1.txt
          --File2.txt              
        --FolderAA2
          --File1.txt
          --File2.txt
        --FolderAA3
     --FolderAB
       --File8.txt
     --FolderAC
       --File9.txt

This hierarchy is dynamic

Additional Question: Is there any GUI tool to copy blob data to target storage account?

解决方案

UPDATE

According to your description, I modified it in the official sample code. It is already possible to completely copy the data in one container to another account, and the code has been uploaded to Github.

To use this sample code, you need to modify the App.Config file. Formal use to the production environment needs to be perfected.

https://github.com/Jason446620/BlobContainerCopy

PRIVIOUS

You can refer to the code in this post for copy operation. If the solution in this post does not help you, please let me know and I will continue to follow up to help you solve the problem.

And u can download Azure Storage Explorer is the GUI tool to copy datas.

这篇关于存储Blob复制操作期间出错-实体的当前状态不允许所请求的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆