Azure / azure-storage-net

Microsoft Azure Storage Libraries for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Returned blob uri's are partly encoded when uploading blobs

KasperPurunen opened this issue · comments

Which service(blob, file, queue, table) does this issue concern?

Azure Blob Storage

Which version of the SDK was used?

Azure.Blob.Storage 12.7.0

Which platform are you using? (ex: .NET Core 2.1)

.NET Core 3.1, .NET 5

What problem was encountered?

Slashes '/' of virtual paths are encoded for blob uri's. E.g. http://127.0.0.1:10000/devstoreaccount1/container/virtualpath%2FfileNameWithExtension.txt

This is not the case with the previous "version" of the the package. This was tested with Microsoft.Azure.Storage.Blob 11.2.2
The following uri is returned with mentioned version of the package: http://127.0.0.1:10000/devstoreaccount1/container/virtualpath/filenamewithextension.txt

Note: In this example the uris are pointing towards a local environment but the issue occurs for storage accounts in azure as well and for azurite.

How can we reproduce the problem in the simplest way?

` public class UploadBlob
{
private readonly BlobServiceClient _blobServiceClient;

    public UploadBlob()
    {
        _blobServiceClient = new BlobServiceClient("UseDevelopmentStorage=true");
    }

    public async Task<Uri> Upload()
    {
        var containerClient = _blobServiceClient.GetBlobContainerClient("newblob");
        await containerClient.CreateIfNotExistsAsync(PublicAccessType.Blob);
        var blockBlobClient = containerClient.GetBlockBlobClient("virtualpath/fileNameWithExtension.txt");
        using (var stream = new MemoryStream(GetRandomFile()))
        {
            await blockBlobClient.UploadAsync(stream, new BlobUploadOptions());
        }

        return blockBlobClient.Uri;
    }

    private static byte[] GetRandomFile()
    {
        var data = new byte[1 * 1024 * 1024];
        var rng = new Random();
        rng.NextBytes(data);

        return data;
    }
}`

Have you found a mitigation/solution?

We have written extension methods for some of our solutions to first decode the uri before returning it.