2

I already know how to create a download link using SAS to create a downloadable link for a Blob in Azure as per the docs. Using this code:

sas = generate_blob_sas(
  account_name="account",
  container_name="container",
  blob_name="myblob",
  account_key="accountKey",
  permission=BlobSasPermissions(read=True),
  expiry=datetime.utcnow() + timedelta(hours=1)
)
blob_url = f'https://account.blob.core.windows.net/container/a?{sas}'

However is this possible for File shares too? I want to create the sas but for a File Share

Update:

I was able to do it from the Azure Storage Explorer, by right clicking on the file and clicking "Get Shared Access Signature".

I also then tried to use the code:

sas_token = generate_account_sas(
    account_name="acc",
    account_key="key",
    resource_types=ResourceTypes(service=True),
    permission=AccountSasPermissions(read=True),
    expiry=datetime.utcnow() + timedelta(hours=1)
)

But this did not work.

Tom
  • 47,574
  • 2
  • 16
  • 29
mp252
  • 453
  • 1
  • 6
  • 18

1 Answers1

0

Yes, you can certainly do that. However, you would need to use azure-storage-file-share package instead of blob.

The methods you are looking for are generate_share_sas for generating SAS URL for a File Share or generate_file_sas for generating SAS URL for a file inside a File Share.

You can learn more about this SDK here: https://learn.microsoft.com/en-us/azure/storage/files/storage-python-how-to-use-file-storage?tabs=python.

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241