Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] getMetadata returns only nulls #38913

Closed
MichaelVonB opened this issue Feb 23, 2024 · 2 comments
Closed

[BUG] getMetadata returns only nulls #38913

MichaelVonB opened this issue Feb 23, 2024 · 2 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed The Azure SDK team member assisting with this issue believes it to be addressed and ready to close. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Storage Storage Service (Queues, Blobs, Files)

Comments

@MichaelVonB
Copy link

Describe the bug
We upload blob with metaData and query them later. However the metadata always return null even tough I can see them in the azure portal.

Exception or Stack Trace
n/a

To Reproduce
see code below

Code Snippet

BlobParallelUploadOptions options =
            new BlobParallelUploadOptions(byteArrayInputStream)
                .setRequestConditions(new BlobRequestConditions().setIfNoneMatch(Constants.HeaderConstants.ETAG_WILDCARD)) // sets overwrite files to false
                .setMetadata(Map.of("foo", "bar"))
                .setHeaders(jsonHeaders);

blobClient.uploadWithResponse(options, null, Context.NONE);

and query them later on essentially like this

BlobContainerClient blobContainerClient = blobServiceClient.getBlobContainerClient("my-blob-container-client");
List<Map<String, String>> metaDataList = blobContainerClient.listBlobs().stream()
            .map(BlobItem::getMetadata)
            .toList();

But this will be a List of nulls. However I can see in the azure portal that the meta data is filled.
This works but I would expect the other solution to work aswell

List<Map<String, String>> metaDataListFull = blobContainerClient.listBlobs().stream()
            .map(it -> blobContainerClient.getBlobClient(it.getName()))
            .map(it -> it.getProperties().getMetadata())
            .toList();

Add the code snippet that causes the issue.

Expected behavior
I would expect BlobItem::getMetadata to return the metadata and not null.

Screenshots
n/a

Setup (please complete the following information):

  • OS: macOS / OpenShift
  • IDE: IntelliJ / -
  • Library/Libraries: azure-storage-blob-12.25.1
  • Java version 17
  • App Server/Environment: Tomcat
  • Frameworks:Spring Boot
@alzimmermsft
Copy link
Member

Thanks for filing this issue @MichaelVonB.

I believe you're running into this problem as there aren't any includes set in the listBlobs call. This document goes over the REST API details on how to include additional information in the response BlobItem:

https://learn.microsoft.com/rest/api/storageservices/list-blobs?tabs=microsoft-entra-id#metadata-in-the-response

And here is an example of the updated Java code:

BlobContainerClient blobContainerClient = blobServiceClient.getBlobContainerClient("my-blob-container-client");
List<Map<String, String>> metaDataList = blobContainerClient.listBlobs(new ListBlobsOptions().setDetails(new BlobListDetails().setRetrieveMetadata(true)), null).stream()
            .map(BlobItem::getMetadata)
            .toList();

And here is a test we run that validates the behavior:

https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/ContainerApiTests.java#L819

@alzimmermsft alzimmermsft self-assigned this Feb 23, 2024
@alzimmermsft alzimmermsft added issue-addressed The Azure SDK team member assisting with this issue believes it to be addressed and ready to close. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Storage Storage Service (Queues, Blobs, Files) customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Feb 23, 2024
@MichaelVonB
Copy link
Author

Thank you for your quick supply. This fixed the issue. My bad i missed this.
For local development we are using azurite and there metadata are always populated regardless of ListBlobsOptions so we never searched in that direction.

@github-actions github-actions bot locked and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed The Azure SDK team member assisting with this issue believes it to be addressed and ready to close. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

2 participants