Search code examples
javaazureazure-storage-files

Using the Java SDK, how to set metadata on a file in Azure Storage File Service?


I've got some Java code to create a new file on an Azure Storage File Service (Azure's SMB file share feature), and I'm trying to add metadata to that com.microsoft.azure.storage.file.CloudFile object:

final HashMap<String, String> metaData = new HashMap<>();
metaData.put("tag", value);
cloudFile.setMetadata(metaData);

If I immediately perform a getMetadata() call on that same CloudFile object, it's there. However, after the program exits and I view the file in Azure Portal, there's no metadata to be seen. I just wrote a separate test program to create a new CloudFile object referencing that file, and it also is unable to retrieve the metadata.

Is there something else I have to do to "persist" my metadata after setting it? BTW, I've successfully done this to Blob Store objects, but this is the first time trying it with File Service objects.


Solution

  • Please call uploadMetadata() method after setting the metadata.

    So your code would be:

    final HashMap<String, String> metaData = new HashMap<>();
    metaData.put("tag", value);
    cloudFile.setMetadata(metaData);
    cloudFile.uploadMetadata();