0
votes

I have typescipt application which uploads the files to Azure blob storage(Private access). Now I need to view the files in browser from the blob URL. How can we view the private blob files from blob URL. I have SAS token associated to that storage account. But appending the SAS token to the blob URL is not working. Please suggest on the way to achieve this.

URL: https://teststorage.blob.core.windows.net/container1/folder2/forest.jpg

URL with SAS token: https://teststorage.blob.core.windows.net/container1/folder2/forest.jpg?

1
But appending the SAS token to the blob URL is not working. - What do you mean by this? What is not working? Please edit your question and include these details. Also share the SAS token (you can obfuscate things like account name and sig portion of the SAS token) in the question.Gaurav Mantri
How do you get the SAS token? Could you share the steps?Pamela Peng

1 Answers

0
votes

I guess the SAS token you got is wrong. You could try to generate the SAS token in Azure Portal(navigate to your blob -> Generate SAS), and get blob with GET https://<storage-name>.blob.core.windows.net/<container-name>/myblob.txt?<sas-token>.

enter image description here

The sample code using generateBlobSASQueryParameters to generate the container SAS token. If you want the blob SAS, add blobName to parameters.

var storage = require("@azure/storage-blob")

// Use StorageSharedKeyCredential with storage account and account key
const sharedKeyCredential = new storage.StorageSharedKeyCredential(account, accountKey);

var expiryDate = new Date();
startDate.setTime(startDate.getTime() - 5*60*1000);
expiryDate.setTime(expiryDate.getTime() + 24*60*60*1000);

const containerSAS = storage.generateBlobSASQueryParameters({
    expiresOn : expiryDate,
    permissions: storage.ContainerSASPermissions.parse("rwl"),
    protocol: storage.SASProtocol.Https,
    containerName: containerName,
    startsOn: startDate,
    version:"2018-03-28"
}, sharedKeyCredential).toString();

You could test your SAS token with AnonymousCredential in typescipt sample.