Azure / azure-storage-java

Microsoft Azure Storage Library for Java
https://docs.microsoft.com/en-us/java/api/overview/azure/storage
MIT License
189 stars 163 forks source link

CloudFile.setMetadata() doesn't seem to stick #497

Closed sec23206 closed 4 years ago

sec23206 commented 4 years ago

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

File service

Which version of the SDK was used?

Please note that if your issue is with v11, we are recommending customers either move back to v11 or move to v12 (currently in preview) if at all possible. Hopefully this resolves your issue, but if there is some reason why moving away from v11 is not possible at this time, please do continue to ask your question and we will do our best to support you. The README for this SDK has been updated to point to more information on why we have made this decision.

Am using v8.3.0 of the Azure Storage Client SDK (https://mvnrepository.com/artifact/com.microsoft.azure/azure-storage)

What problem was encountered?

When using the setMetadata() method of the CloudFile class, I can immediately perform a getMetadata() and I can retrieve the data I just set. However, when I try to view the metadata of that file in the storage account via the Azure Portal, there is no metadata visible. This is an example of the code I'm using to set the metadata:

final HashMap<String, String> metaData = new HashMap<>(); metaData.put("Promoter", mudID); cloudFileRef.setMetadata(metaData);

Have you found a mitigation/solution?

Not yet.

sec23206 commented 4 years ago

A follow on to this, I wrote some additional code to create a new CloudFile object for the newly created file and retrieve its metadata, and none exist. Is there something you have to do to "persist" metadata after setting it?

jaschrep-msft commented 4 years ago

Hi @sec23206. Metadata and properties use a local cache. Get and set operate on the local caches only. uploadMetadata() and uploadProperties() each push the current cached data to the service, while downloadAttributes() refreshes the local caches for both properties and metadata with the current state of the service. This should resolve your issue.

We understand this model can be somewhat confusing. This was one of our motivations for redesigning the client libraries from the ground up. If you are interested, you can look at this repo for our work in creating a unified azure experience.

sec23206 commented 4 years ago

That was the issue and I'm now able to correctly set metadata. It was after I was quite a ways into development that I realized I was using an older version of the Azure JDK, so will look to move to the newer libraries at the next major update. Thanks for the help!