I have a SAS token for a specific folder, which in itself of course has more folders and blobs. I am looking to create a Service or Container client to allow me to iterate on the folders/blobs in this folder.
I’ve tried using a serviceclient, but of course it’s not authorized.
I’ve tried using a containerclient, but this fails on the URI with an invalid connection string
new BlobContainerClientBuilder().connectionString("https://{blobacct}.blob.core.windows.net/{container}/{folder}?sp=...
The above is the attempt which fails on invalid connection string.
2
Answers
Looking at the sdk github documentation, you can do someting like that:
As per this ask,
So, you might be using ADLS gen2 storage account. You can use ADLS gen2 Java SDK for this. First, create
DataLakeDirectoryClient
like below.The above code is referred from this doc.
Then use
listpaths()
on this object to get the list of files/directories from your folder. You can go through this documentation to know more about this method.Coming to your error, the SAS of yours is at the folder level but to list the blobs it needs container level SAS. That is why it is giving the authorization error.
If you want to list the files/directories using Blob storage SDK, you can achieve your requirement using the below code where it uses a recursive function and some Array lists.
Here, when I have used
listBlobs()
method orlistBlobsByHierarchy("/")
, I got same error as it is accessing container level information.Result: