How to ensure a blob filename is unique on Azure Storage

1.8k Views Asked by At

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

1

There are 1 best solutions below

0
On BEST ANSWER

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.