Currently I have code in node JS that generates SAS tokens for blobs within a specified Azure Storage container. I want to be able to generate a SAS token that will grant the user access to the entire container itself, rather than generating tokens for each individual blob. How would I go about doing that? Below is the code that currently generates tokens for blobs.
const containerName = "samplecontainer";
const blobName = "sample.csv";
const account = "sampleaccount";
const key = process.env["StorageConKey"]; // storage connection key
const credentials = new storage.StorageSharedKeyCredential(account, key);
const blobSASToken = storage.generateBlobSASQueryParameters({
containerName,
blobName,
permissions: storage.BlobSASPermissions.parse("r"),
startsOn: new Date(),
expiresOn: new Date(new Date().valueOf() + 60000)
},
credentials).toString();
2
Answers
Have you tried with
permissions: storage.ContainerSASPermissions.parse("r")
?Here the relative documentation: https://learn.microsoft.com/en-us/javascript/api/@azure/storage-blob/containersaspermissions?view=azure-node-latest
You can use the below node.js code to create a container SAS token and container URL with SAS-token.
Code:
Output:
Reference:
Create a service SAS for a container or blob with JavaScript – Azure Storage | Microsoft Learn