Package version:

Function generateBlobSASQueryParameters

  • ONLY AVAILABLE IN NODE.JS RUNTIME.

    Creates an instance of SASQueryParameters.

    Only accepts required settings needed to create a SAS. For optional settings please set corresponding properties directly, such as permissions, startsOn and identifier.

    WARNING: When identifier is not provided, permissions and expiresOn are required. You MUST assign value to identifier or expiresOn & permissions manually if you initial with this constructor.

    Fill in the required details before running the following snippets.

    Example usage:

    import {
    StorageSharedKeyCredential,
    generateBlobSASQueryParameters,
    ContainerSASPermissions,
    SASProtocol,
    } from "@azure/storage-blob";

    const account = "<account>";
    const accountKey = "<accountkey>";
    const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
    const containerName = "<container name>";

    // Generate service level SAS for a container
    const containerSAS = generateBlobSASQueryParameters(
    {
    containerName, // Required
    permissions: ContainerSASPermissions.parse("racwdl"), // Required
    startsOn: new Date(), // Optional
    expiresOn: new Date(new Date().valueOf() + 86400 * 1000), // Required. Date type
    ipRange: { start: "0.0.0.0", end: "255.255.255.255" }, // Optional
    protocol: SASProtocol.HttpsAndHttp, // Optional
    version: "2016-05-31", // Optional
    },
    sharedKeyCredential,
    ).toString();

    Example using an identifier:

    import {
    StorageSharedKeyCredential,
    BlobServiceClient,
    ContainerSASPermissions,
    generateBlobSASQueryParameters,
    } from "@azure/storage-blob";

    const account = "<account>";
    const accountKey = "<accountkey>";
    const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
    const blobServiceClient = new BlobServiceClient(
    `https://${account}.blob.core.windows.net`,
    sharedKeyCredential,
    );

    const containerName = "<container name>";
    const containerClient = blobServiceClient.getContainerClient(containerName);

    // Generate service level SAS for a container with identifier
    // startsOn & permissions are optional when identifier is provided
    const identifier = "unique-id";
    await containerClient.setAccessPolicy(undefined, [
    {
    accessPolicy: {
    expiresOn: new Date(new Date().valueOf() + 86400 * 1000), // Date type
    permissions: ContainerSASPermissions.parse("racwdl").toString(),
    startsOn: new Date(), // Date type
    },
    id: identifier,
    },
    ]);

    const containerSAS = generateBlobSASQueryParameters(
    {
    containerName, // Required
    identifier, // Required
    },
    sharedKeyCredential,
    ).toString();

    Example using a blob name:

    import {
    StorageSharedKeyCredential,
    generateBlobSASQueryParameters,
    BlobSASPermissions,
    SASProtocol,
    } from "@azure/storage-blob";

    const account = "<account>";
    const accountKey = "<accountkey>";
    const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);

    const containerName = "<container name>";
    const blobName = "<blob name>";

    // Generate service level SAS for a blob
    const blobSAS = generateBlobSASQueryParameters(
    {
    containerName, // Required
    blobName, // Required
    permissions: BlobSASPermissions.parse("racwd"), // Required
    startsOn: new Date(), // Optional
    expiresOn: new Date(new Date().valueOf() + 86400 * 1000), // Required. Date type
    cacheControl: "cache-control-override", // Optional
    contentDisposition: "content-disposition-override", // Optional
    contentEncoding: "content-encoding-override", // Optional
    contentLanguage: "content-language-override", // Optional
    contentType: "content-type-override", // Optional
    ipRange: { start: "0.0.0.0", end: "255.255.255.255" }, // Optional
    protocol: SASProtocol.HttpsAndHttp, // Optional
    version: "2016-05-31", // Optional
    },
    sharedKeyCredential,
    ).toString();

    Parameters

    Returns SASQueryParameters

  • ONLY AVAILABLE IN NODE.JS RUNTIME.

    Creates an instance of SASQueryParameters. WARNING: identifier will be ignored when generating user delegation SAS, permissions and expiresOn are required.

    Example usage:

    import {
    BlobServiceClient,
    generateBlobSASQueryParameters,
    ContainerSASPermissions,
    SASProtocol,
    } from "@azure/storage-blob";
    import { DefaultAzureCredential } from "@azure/identity";

    const account = "<account>";
    const blobServiceClient = new BlobServiceClient(
    `https://${account}.blob.core.windows.net`,
    new DefaultAzureCredential(),
    );

    const containerName = "<container name>";
    const accountName = "<account name>";
    const startsOn = new Date();
    const expiresOn = new Date(new Date().valueOf() + 86400 * 1000);

    // Generate user delegation SAS for a container
    const userDelegationKey = await blobServiceClient.getUserDelegationKey(startsOn, expiresOn);
    const containerSAS = generateBlobSASQueryParameters(
    {
    containerName, // Required
    permissions: ContainerSASPermissions.parse("racwdl"), // Required
    startsOn, // Optional. Date type
    expiresOn, // Required. Date type
    ipRange: { start: "0.0.0.0", end: "255.255.255.255" }, // Optional
    protocol: SASProtocol.HttpsAndHttp, // Optional
    version: "2018-11-09", // Must greater than or equal to 2018-11-09 to generate user delegation SAS
    },
    userDelegationKey, // UserDelegationKey
    accountName,
    ).toString();

    Parameters

    • blobSASSignatureValues: BlobSASSignatureValues
    • userDelegationKey: UserDelegationKey

      Return value of blobServiceClient.getUserDelegationKey()

    • accountName: string

    Returns SASQueryParameters