2

I want to ensure the files I put on Azure storage are unique. My naive and badly performing approach is to use Java UUID to generate unique id and then check to see if the blob exists, and then write the file if not or regenerate new filename and write otherwise. This requires two round trips... is there a better way? One would hope Azure could do this. I'm using the azure-storage-blob Java SDK 12.8.0

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
user2395365
  • 1,991
  • 4
  • 18
  • 34
  • I encountered this in a scenario where I needed a document upload to be idempotent. If you let it upload the same doc id multiple times, then you have non-unique documents in the storage. SO: what is the solution to uniqueness in that case? – djangofan Oct 26 '22 at 16:40

1 Answers1

2

The Azure itself does not have this feature to do this.

Your solution should be the best one: use UUID(since UUID is globally unique, and only a very very little chance to be duplicate) as file name and then check if it exists.

Otherwise, you need to loop all the blob first->and store all the names locally, eg. store names in a list; when uploading a new file -> check the name locally from the list, then determine if it's there or not.

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60