title | titleSuffix | description | author | ms.service | ms.topic | ms.date | ms.author | ms.reviewer | ms.devlang | ms.custom |
---|---|---|---|---|---|---|---|---|---|---|
Create a service SAS for a container or blob with JavaScript |
Azure Storage |
Learn how to create a service shared access signature (SAS) for a container or blob using the Azure Blob Storage client library for JavaScript. |
pauljewellmsft |
azure-blob-storage |
how-to |
01/19/2023 |
pauljewell |
nachakra |
javascript |
devx-track-javascript, engagement-fy23, devx-track-js, devguide-js |
[!INCLUDE storage-auth-sas-intro-include]
This article shows how to use the storage account key to create a service SAS for a container or blob with the Blob Storage client library for JavaScript.
The following code example creates a SAS for a container. If the name of an existing stored access policy is provided, that policy is associated with the SAS. If no stored access policy is provided, then the code creates an ad hoc SAS on the container.
A service SAS is signed with the account access key. Use the StorageSharedKeyCredential class to create the credential that is used to sign the SAS. Next, call the generateBlobSASQueryParameters function providing the required parameters to get the SAS token string.
:::code language="javascript" source="~/azure-storage-snippets/blobs/howto/JavaScript/NodeJS-v12/SAS.js" id="Snippet_ContainerSAS":::
The following code example creates a SAS on a blob. If the name of an existing stored access policy is provided, that policy is associated with the SAS. If no stored access policy is provided, then the code creates an ad hoc SAS on the blob.
To create a service SAS for a blob, call the generateBlobSASQueryParameters function providing the required parameters.
:::code language="javascript" source="~/azure-storage-snippets/blobs/howto/JavaScript/NodeJS-v12/SAS.js" id="Snippet_BlobSAS":::
[!INCLUDE storage-blob-javascript-resources-include]