Pardha
Pardha

Reputation: 103

How to view/download private blobs from blob URL?

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?

Upvotes: 0

Views: 10428

Answers (1)

unknown
unknown

Reputation: 7483

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.

Upvotes: 0

Related Questions