1
votes

I am trying to create a URI with a Shared Access Signature for a single file in an azure blob storage. I want to create this on my backend and send the link to my angular frontend so that the user can directly download the file.

I have found a similar example for C# here: How to download a file to browser from Azure Blob Storage

However I´m having trouble finding the correct way for NodeJS. I looked at https://docs.microsoft.com/de-de/rest/api/storageservices/create-user-delegation-sas however I´m not sure how to use that information.

1

1 Answers

0
votes

Here is a sample code to get blob sas url.

var azure = require('azure-storage');
var blobService = azure.createBlobService('storage connection');
// Create a SAS token that expires in an hour
    // Set start time to five minutes ago to avoid clock skew.
    var startDate = new Date();
    startDate.setMinutes(startDate.getMinutes() - 5);
    var expiryDate = new Date(startDate);
    expiryDate.setMinutes(startDate.getMinutes() + 60);

    permissions = azure.BlobUtilities.SharedAccessPermissions.READ;

    var sharedAccessPolicy = {
        AccessPolicy: {
            Permissions: permissions,
            Start: startDate,
            Expiry: expiryDate
        }
    };
    var container='test';
    var blobName='test.txt';
    var sasToken = blobService.generateSharedAccessSignature(container, blobName, sharedAccessPolicy);
    var url=blobService.getUrl(container,blobName,sasToken);
    console.log(url);

enter image description here