question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Azure batch delete blobs fails if blob contains cyrillic characters

See original GitHub issue

Describe the bug Consider the following blob name which is uploaded successfully to Azure - здраве-и-красота-от-природатаjpg–xfgqfvhj.axp.jpg Deleting it using BlobBatchClient.DeleteBlobsAsync returns Azure.RequestFailedException and blobs are not deleted. Deleting other blobs having the same name structure but containing only latin characters are deleted successfully.

Expected behavior Delete selected blobs.

Actual behavior An exception is thrown:

Azure.RequestFailedException: Invalid response Status: 202 (Accepted)

Headers: Transfer-Encoding: chunked Server: Windows-Azure-Blob/1.0,Microsoft-HTTPAPI/2.0 x-ms-request-id: ca75dfea-301e-0037-034f-797a43000000 x-ms-version: 2020-08-04 x-ms-client-request-id: 92f5a687-8b59-4782-afff-8cd7f89b0ca3 Date: Thu, 15 Jul 2021 08:01:05 GMT Content-Type: multipart/mixed; boundary=batchresponse_34a11e24-f92f-4988-95fe-d61c91ab93c2

—> System.InvalidOperationException: Expected 2 responses for the batch request, not 1. at Azure.Storage.Blobs.Specialized.BlobBatchClient.UpdateOperationResponses(IList1 messages, Response rawResponse, Stream responseContent, String responseContentType, Boolean throwOnAnyFailure, Boolean async, CancellationToken cancellationToken) --- End of inner exception stack trace --- at Azure.Storage.Blobs.Specialized.BlobBatchClient.UpdateOperationResponses(IList1 messages, Response rawResponse, Stream responseContent, String responseContentType, Boolean throwOnAnyFailure, Boolean async, CancellationToken cancellationToken) at Azure.Storage.Blobs.Specialized.BlobBatchClient.SubmitBatchInternal(BlobBatch batch, Boolean throwOnAnyFailure, Boolean async, CancellationToken cancellationToken) at Azure.Storage.Blobs.Specialized.BlobBatchClient.DeleteBlobsInteral(IEnumerable1 blobUris, DeleteSnapshotsOption snapshotsOption, Boolean async, CancellationToken cancellationToken) at Azure.Storage.Blobs.Specialized.BlobBatchClient.DeleteBlobsAsync(IEnumerable1 blobUris, DeleteSnapshotsOption snapshotsOption, CancellationToken cancellationToken) at Smartalize.Web.Services.Implementations.StorageService.UnAssociateProductMedia(IEnumerable1 oldEntities, IEnumerable1 currentEntities, BlobBatchClient batchClient, BlobContainerClient container) in

To Reproduce

  1. Create a file with name - здраве-и-красота-от-природатаjpg–xfgqfvhj.axp.jpg
  2. Upload it to an Azure container
  3. Try to delete it using BlobBatchClient.DeleteBlobsAsync(IEnumerable<Uri>, DeleteSnapshotsOption, CancellationToken) method

Environment:

  • Azure.Storage.Blobs 12.9.1, Azure.Storage.Blobs.Batch 12.9.1
  • .NET SDK (reflecting any global.json): Version: 5.0.302 Commit: c005824e35

Runtime Environment: OS Name: Windows OS Version: 10.0.19043 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.302\

Host (useful for support): Version: 5.0.8 Commit: 35964c9215

  • Visual Studio 16.10.3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
gmantricommented, Jul 15, 2021

@intenzive - I too think so. Considering the REST API accepts only container name and blob name, SDK should provide an override to specify string instead of URI.

1reaction
gmantricommented, Jul 15, 2021

I posted an answer on your Stack Overflow question as well. Pasting the same answer here for completeness.

private static string connectionString =
    "DefaultEndpointsProtocol=https;AccountName=account-name;AccountKey=account-key==";
private static string containerName = "container-name";

static async Task Main(string[] args)
{
    BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
    BlobBatchClient batchClient = new BlobBatchClient(blobServiceClient);
    
    List<string> blobNames = new List<string>()
    {
        "здраве-и-красота-от-природатаjpg--xfgqfvhj.axp.webp",
        "thumbs/здраве-и-красота-от-природатаjpg--xfgqfvhj.axp.webp"
    };
    BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
    List<BlobClient> blobClients = blobNames.Select(b => containerClient.GetBlobClient(b)).ToList();
    List<Uri> blobsToBeDeleted = blobClients.Select(b => new Uri(Uri.EscapeUriString(b.Uri.AbsoluteUri))).ToList();
    await batchClient.DeleteBlobsAsync(blobsToBeDeleted);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] unable to batch delete a blob with Chinese ...
Looks like there's a problem in the SDK with how the blob name is being added to the Batch of blobs to delete....
Read more >
Azure blob batch delete cyrillic characters
I am able to upload blobs containing cyrillic characters using Azure.Storage.Blobs 12.9.1 but then am unable to batch delete them using Azure.
Read more >
Azure Storage Services REST API; Blob Batch; DELETE ...
Hi all, I'm having trouble using the "Blob Batch"-operation of the Blob ... Delete all three blobs at once BlobBatchClient batch = service....
Read more >
Uploading blob or block content fails in Azure Blob Storage
Remove the uncommitted blocks by implementing one of these solutions. Solution 1: Wait for garbage collection to pick up the uncommitted data.
Read more >
azure.storage.blob.appendblobservice. ...
:type ~azure.storage.common. ... Sends a batch of multiple blob delete requests. ... The data returned does not include the container's list of blobs....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found