generateSasUrl url-encodes slashes in blob name, breaks url
See original GitHub issue- Package Name: @azure/storage-blob
- Package Version: 12.4.0
- Operating system: Linux lubuntu 18.04
- nodejs
- version: 14.15.4
Describe the bug generateSasUrl url-encodes slashes in blob name, resulting in broken url
To Reproduce Steps to reproduce the behavior:
- upload a blob with name:
foo/123/bar.jpg
- generate a SAS url using @azure/storage-blob:
const { BlobServiceClient, StorageSharedKeyCredential, BlobSASPermissions } = require('@azure/storage-blob');
const config = {container: 'test', account: 'foo', accountKey: '...'}; // using a Storage account access key
const sharedKeyCredential = new StorageSharedKeyCredential(config.account, config.accountKey);
const blobServiceClient = new BlobServiceClient(`https://${config.account}.blob.core.windows.net`, sharedKeyCredential);
const containerClient = blobServiceClient.getContainerClient(config.container);
const blobClient = containerClient.getBlobClient('foo/123/bar.jpg');
console.log(
blobClient.generateSasUrl({
permissions: new BlobSASPermissions({ read: true }),
expiresOn: new Date(Date.now() + 86400 * 1000),
})
);
outputs
Promise {
'https://foo.blob.core.windows.net/test/foo%2F123%2Fbar.jpg?sv=2020-04-08&se=2021-01-23T08%3A39%3A24Z&sr=b&sig=i....%2BZU%3D'
}
where slashes are url-encoded as “%2F”, which makes link not work properly
Expected behavior In comparison, it’s working from Azure portal dashboard as expected, if I click on the blob file and then click “Generate SAS token and URL” the url is well formatted and they work if I request them:
https://foo.blob.core.windows.net/test/foo/123/bar.jpg?sp=r&st=2021-01-22T08:26:41Z&se=2021-01-22T16:26:41Z&spr=https&sv=2019-12-12&sr=b&sig=mlulH.....HeYTqE%3D
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Upgrading Azure Blob API 11->12, leading slash in blob name ...
One possible workaround is to create an instance of BlobClient using the full URL of the blob. That way the leading slashes are...
Read more >@azure/storage-blob package | Microsoft Learn
A BlobClient represents a URL to an Azure Storage blob; the blob may be a block blob, append blob, ... Options to configure...
Read more >Azure blob storage generate temporary public url for private file.
This article demonstrates how to generate a temporary public URL to access a private file that resides inside the Azure blob storage which ......
Read more >How To Use a SAS URL to Upload Files to Azure Blob Storage
In this episode, we'll show you how to use Azure Blob Storage SAS URL's to upload data and files to Azure Blob StorageHow...
Read more >How to Create a Azure Blob Shared Access Signature (SAS ...
Azure Blobs allows for Shared Access Signature (SAS) Tokens to be created to ... the DDP_RESOURCE_URL is appended to the base URL with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The real cause is you were not correctly constructing a permission with
new BlobSASPermissions({ read: true })
. We may consider to support this way. But for now, you should use eitheror
Note that both
parse()
andfrom()
are static methods, so you don’t need to call it with thenew
operator.You are welcome. Will close this issue now. Feel free to re-open it if any help is needed from us regarding it.