Search code examples
azureazure-data-lake-gen2sas-tokenshared-access-signatures

List folder in Azure Gen2 storage account with sas


I generated a sas token with the list permission for a folder in a datalake storage account gen2.
Howerver when I try to access it with an httpGet request, I get AuthorizationPermissionMismatch error This request is not authorized to perform this operation using this permission
I know that to list a container with httpRequest we have to add &comp=list&restype=container in the queryString. Is there any specific param to add for listing a folder
Thanks


Solution

  • Once you have generated the SAS token on the container level using the required permissions. You can add a directory filter in the rest API like below :

    https://<StorageURL>/<Container>?directory=<DirectoryName>&restype=container&comp=list&<SASToken>
    

    I tested the same in my environment . I created ADLS Gen 2 Storage account , a test container and then a directory named as Folder and added few files in it as shown below :

    enter image description here

    Then using SAS generated on container level , I called the below Rest API :

    https://adlsgen2ansuman.blob.core.windows.net/test?directory=folder&restype=container&comp=list&sp=racwdlmeop&st=2022-02-03T06:55:43Z&se=2022-02-03T14:55:43Z&spr=https&sv=2020-08-04&sr=c&sig=xxxxxxxxxxxxxxxxxx
    

    Output:

    enter image description here