Azure / Azure/Azurite

[BUG] Retrieving Blob metadata with Blob SDK v12 always returns NULL

Open
#759 5 comments 0 reactions 2 assignees Claimed by @blueww View on GitHub
alignment blob-storage stale
Dominant language
TypeScript
Stars
2.3k
Forks
393
Avg merge
1d 20h
Merged PRs (30d)
36

Description

**Describe the bug**
I can successfully add Metadata to a Blob using the Storage Blob SDK v12. I can see in Azure Portal and in the Storage Explorer that the metadata has been added to my blob, but when I retrieve the blob with the SDK, the metadata is always NULL.

***Exception or Stack Trace***
No errors or exceptions when retrieving.

**To Reproduce**
- Create a new Blob with the SDK
- Add Metadata to the new Blob
- Retrieve the Blob and try to read the metadata

***Code Snippet***
```
package com.blobs.quickstart;

import com.azure.core.http.HttpClient;
import com.azure.core.http.ProxyOptions;
import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
import com.azure.storage.blob.*;
import com.azure.storage.blob.models.*;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import java.io.*;
import java.net.InetSocketAddress;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
* Creating and retrieving Metadata
*/
public class CreatingMetadataApp
{
private static String connectionString;

private static BlobServiceClient blobServiceClient;

private static BlobContainerClient containerClient;
private static BlobContainerProperties containerProperties;

private static BlobClient blobClient;

private static String localPath;
private static String fileName;

public static void main(String[] args) throws IOException
{
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.INFO);

System.out.println("Creating and retrieving metadata\n");

getConnectionString();

connectToAzure();

getContainers();

uploadBlobsToContainers();

listBlobsInContainer();
}

private static void getConnectionString()
{
connectionString = System.getenv("CONNECT_STR");

System.out.printf("connectionString = %s%n%n", connectionString);
}

private static void connectToAzure()
{
// Create a BlobServiceClient object WITHOUT PROXY which will be used to create a container client
blobServiceClient = new BlobServiceClientBuilder().connectionString(connectionString).buildClient();
}

private static void getContainers()
{
// Get a standard container and an immutable container
containerClient = blobServiceClient.getBlobContainerClient("creating-metadata-1");
containerProperties = containerClient.getProperties();

System.out.printf("Container: %s - hasImmutabilityPolicy = %s%n", containerClient.getBlobContainerName(), containerProperties.hasImmutabilityPolicy());
}

private static void uploadBlobsToContainers() throws IOException
{
// Create a local file in the ./data/ directory for uploading and downloading
localPath = "./data/";

fileName = "creating-metadata-" + java.util.UUID.randomUUID() + ".txt";

// Write text to the file
try (FileWriter writer = new FileWriter(localPath + fileName, true))
{
writer.write("Testing metadata creation");
}

// Get a reference to a blob
blobClient = containerClient.getBlobClient(fileName);

System.out.println("\nUploading to Blob storage as blob:\n\t" + blobClient.getBlobUrl());

Map metadataMap = new HashMap()
{
{
put("dsCreatedTime", LocalDateTime.now().toString());
}
};

// Upload the blob
blobClient.uploadFromFile(localPath + fileName);
blobClient.setMetadata(metadataMap);
}

private static void listBlobsInContainer()
{
System.out.printf("%nListing blobs for container %s%n", containerClient.getBlobContainerName());

// List the blob(s) in the container.
for (BlobItem blobItem : containerClient.listBlobs())
{
Map metadata = blobItem.getMetadata();

System.out.println("\t" + blobItem.getName() + "\tdsCreatedTime = " + metadata.get("dsCreatedTime"));
}
}
}
```

**Expected behavior**
Since I have confirmed that the Metadata has been successfully saved, I should be able to retrieve it with the latest Blob SDK (v12).

**Setup (please complete the following information):**
- OS: Windows 10
- IDE : IntelliJ IDEA
Azure Storage Blob SDK v12

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.