AzureStorageExplorer icon indicating copy to clipboard operation
AzureStorageExplorer copied to clipboard

Unable to view folder containing blob created from Azure Function using [Blob] output to Azurite

Open MartinWilkerson opened this issue 3 years ago • 4 comments

Preflight Checklist

Storage Explorer Version

1.25.0

Regression From

No response

Architecture

i86

Storage Explorer Build Number

20220803.8

Platform

Windows

OS Version

Windows 10

Bug Description

After writing a blob to a folder in Azurite from an Azure Function project using the [Blob] attribute from Microsoft.Azure.Webjobs.Extensions.Storage.Blobs version 5.0.1, Storage Explorer is unable to list blobs in that folder giving the error The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined. The blob can be successfully read using other methods, such as the [Blob] attribute in read mode in a subsequent function invocation. The issue does not occur with actual storage accounts in Azure using the same code with only connection strings changed.

Steps to Reproduce

  1. Create a function app project with a reference to Microsoft.Azure.Webjobs.Extensions.Storage.Blobs version 5.0.1
  2. Configure a connection called 'TestConnection' to use development storage (UseDevelopmentStorage=true)
  3. Run Azurite so it's listening on default ports
  4. Create a blob container in Azurite called testcontainer
  5. Add a function with the following code:
    [FunctionName("TestBlob")]
    public void CreateBlob(
        [HttpTrigger(Microsoft.Azure.WebJobs.Extensions.Http.AuthorizationLevel.Anonymous, "get", Route = "createblob")] HttpRequest req,
        [Blob("testcontainer/1.txt", FileAccess.Write, Connection = "TestConnection")] Stream testBlob)
    {
        var bytes = Encoding.UTF8.GetBytes("hello world");
        testBlob.Write(bytes, 0, bytes.Length);
    }
    
  6. Run the function in the debugger and call it
  7. Open Azure Storage Explorer and navigate to testcontainer

Actual Experience

An error is shown:

The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined

Expected Experience

I am able to view the created blob and download it

Additional Context

No response

MartinWilkerson avatar Aug 08 '22 21:08 MartinWilkerson

This is a known issue to us. The root cause is a combination of Azurite doesn't return empty MD5 hash values and the JavaScript SDK we use assumes the MD5 hash value is always returned. To workaround this issue, you can write some code to commit the correct MD5 hash of the blob in Azurite. The JavaScript SDK has made a fix in their latest version to gracefully handle missing MD5 hash values but we are a little behind so it will have to wait until our 1.26.0.

Related issue: https://github.com/Azure/Azurite/issues/1592

JasonYeMSFT avatar Aug 08 '22 22:08 JasonYeMSFT

Thank you - it turned out to be barely even any code to have the MD5 calculated - changing to using a BlobClient instead of a Stream as the bound parameter and using Upload (or UploadAsync). For any who hit this issue and find this, I found the workaround through Azure Blob storage output binding for Azure Functions and then Azure WebJobs Storage Blobs client library for .NET documentation for an example of using BlobClient.

[FunctionName("TestBlob")]
public void CreateBlob(
    [HttpTrigger(Microsoft.Azure.WebJobs.Extensions.Http.AuthorizationLevel.Anonymous, "get", Route = "createblob")] HttpRequest req,
    [Blob("testcontainer/1.txt", FileAccess.ReadWrite, Connection = "TestConnection")] BlobClient testBlob)
{
    var bytes = Encoding.UTF8.GetBytes("hello world");
    testBlob.Upload(new BinaryData(bytes));
}

Not sure why it sets the MD5 in BlobClient.Upload and not when bound directly to a stream - I did test calling Upload with a stream instead of BinaryData as well - but that's not really something for this project.

MartinWilkerson avatar Aug 10 '22 22:08 MartinWilkerson

@JasonYeMSFT do we want to dedicate this issue (or a separate one) to making sure we update our blob SDK in 1.26?

MRayermannMSFT avatar Aug 10 '22 23:08 MRayermannMSFT

@MRayermannMSFT Yes. I will make sure to upgrade the blob SDK in 1.26.0

JasonYeMSFT avatar Aug 10 '22 23:08 JasonYeMSFT

I also encounter this issue, when writing blob using .NET SDK 12, and connect to the local blob storage

Jasonlhy avatar Sep 08 '22 03:09 Jasonlhy

The same - Storage Explorer version 1.25.1 with azurite https://stackoverflow.com/questions/73765729/upload-file-with-azure-blob-storage-output-binding-for-azure-functions

Marusyk avatar Sep 18 '22 21:09 Marusyk

@JasonYeMSFT since you added the merged label days ago, could you please point us what is the commit on the patch applied, thanks !, or how can we get beta azurite with those changes ?

thanks !

DavidNorena avatar Sep 23 '22 16:09 DavidNorena

@DavidNorena We merged the version update to our next 1.26.0 dev branch. Unfortunately it is not open sourced so you will need to upgrade when it releases. I will update this thread when 1.26.0 become available.

JasonYeMSFT avatar Sep 23 '22 17:09 JasonYeMSFT

This seems to be fixed in the new v1.26.0 release, but does not yet appear in the query for fixed issues in the release notes, as this issue is still open.

panikc avatar Oct 06 '22 09:10 panikc

1.26.0 has been released which upgraded the blob SDK to resolve this issue.

JasonYeMSFT avatar Oct 06 '22 17:10 JasonYeMSFT