0
votes

We have a requirement to validate the folder or a file location which is there in azure-blob-storage container.

Example folder path: wasbs://@.blob.core.windows.net/ Example file path: wasbs://@.blob.core.windows.net//

Would like to validate the file or the folder exists or not before proceeding with my business logic.

Is there any way I can validate the paths using URI? instead of going with storage packages.

Note: We are not allowed to use SAS token to access the storage path. But, we can go with storage key or connection string to connect to storage account from application code.

1
Was the provided answer helpful for you? Please mark as an answer to help the community find relevant answers.Adam Smith - Microsoft Azure

1 Answers

1
votes

wasb is the hdfs compatible API on top of Azure blob storage, if you use HTTP:// , you could perhaps check on the path and the HTTP response you get, 404 probably path/file doesn't exist, 200, file path exists. I hope this helps.

Update: Thanks @Gaurav for the insightful comment,I also added an example on checking the blob status in python, you can do so in other languages as well, you can just plugin the needed information: Storage account name, key, container name, blob name, and you'll get back a boolean value if the blob exists or not:

from azure.storage.blob import BlockBlobService
block_blob_service = BlockBlobService(account_name='', account_key='')

def blob_exists():

        container_name = ""
        blob_name = ""

        exists=(block_blob_service.exists(container_name, blob_name))
        return exists
blobstat = blob_exists()
print(blobstat)