简体   繁体   English

C#+ Azure存储Blob:StorageException:当前有一个挂起的复制操作

[英]C# + Azure Storage blobs: StorageException: There is currently a pending copy operation

I have server that getting a URL of azure blob file (SAS read only) and copy it to another blob in different Storage account. 我有服务器获取azure blob文件的URL(SAS只读)并将其复制到其他存储帐户中的另一个blob。 The copy command is async command ( StartCopyAsync() ). 复制命令是异步命令( StartCopyAsync() )。

Copy the file is only one thing that this server doing, it's doing some more. 复制文件只是该服务器要做的一件事,它要做的更多。 If one (or more) of the other calculation failed, it's throw exception. 如果另一个计算中的一个(或多个)失败,则抛出异常。

When exception occurred, I doing rollback - which mean, delete the file I copied in the first stage. 当发生异常时,我将进行回滚-这意味着删除在第一阶段中复制的文件。 I doing it like this: 我这样做是这样的:

await backupFile.DeleteIfExistsAsync();

The problem 问题

I getting this error code: 我收到此错误代码:

System.AggregateException: One or more errors occurred. (There is currently a pending copy operation.) 
---> Microsoft.WindowsAzure.Storage.StorageException: There is currently a pending copy operation.
 at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token) at Microsoft.WindowsAzure.Storage.Blob.CloudBlob.DeleteIfExistsAsync(DeleteSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)

I guess it because the async copy didn't finished yet... 我猜是因为异步复制尚未完成...

Is this possible to solve it with async Delete command, that will take place after the Copy command done? 是否可以使用异步Delete命令解决该问题,该命令将在复制命令完成后进行?

Any other solution will be welcome. 任何其他解决方案都将受到欢迎。 Thanks! 谢谢!

I would suggest you try the StartAsyncCopy() overload that accepts a CancellationToken . 我建议您尝试接受CancellationTokenStartAsyncCopy()重载。 Once you use that overload, you should be able to cancel the copy operation through the CancellationTokenSource of the CancellationToken you used when you called the method. 使用该重载后,您应该能够通过调用该方法时使用的CancellationTokenCancellationTokenSource取消复制操作。

See CloudBlockBlob.StartCopyAsync Method for all available overloads. 有关所有可用的重载,请参见CloudBlockBlob.StartCopyAsync方法 And you can also take a look at CancellationTokenSource Class on how to use the cancellation mechanism. 您还可以查看有关如何使用取消机制的CancellationTokenSource类

Update 更新

As mentioned in the comment below, you should also take a look at CloudBlob.AbortCopyAsync() in case the operation already started. 如下面的注释中所述,如果操作已经开始,您还应该查看CloudBlob.AbortCopyAsync()

Hope it helps! 希望能帮助到你!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 C# 在 Azure 中的存储容器之间复制 blob - Copy blobs between storage containers in Azure using C# Azure存储Blob,C#,如何确定当前使用的Blob? - Azure storage blobs, C#, how can I determine what blob is currently in use? 在 c# 的私有访问下无法下载 azure 存储 blob - Trouble downloading azure storage blobs under private access in c# Azure Worker角色和Blob存储C#-Microsoft.WindowsAzure.Storage.StorageException:远程服务器返回错误:(400)错误的请求 - Azure Worker role and blob storage c# - Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (400) Bad Request 如何使用 C# 中的 Azure.Storage.Blobs 以 ByteArray 格式从 Azure 存储 blob 中获取文件 - How to get file from Azure storage blob in a ByteArray format using Azure.Storage.Blobs in C# 在 C# 中复制 Azure 存储表 - Copy Azure Storage Tables in C# 在Azure存储Blob上使用.Net Core和C#将图像序列转换为MP4文件 - Convert image sequence to MP4 file using .Net Core and C# on Azure Storage Blobs 使用 C# 在多级文件夹结构中查找 Azure 存储容器中的 Blob - Find Blobs in Azure Storage Container in multi level folder structure using C# 将 blob 从一个 Azure 容器复制到另一个使用 ASP.NET Core 6.0 MVC 和 C# - Copy blobs from one Azure container to another using ASP.NET Core 6.0 MVC with C# C#-将多个Blob保存到Azure帐户 - C# - Save multiple blobs into azure account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM