question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:

  1. upload a blob with name: foo/123/bar.jpg
  2. 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:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ljian3377commented, Jan 25, 2021

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 either

const permission = BlobSASPermissions.from({ read: true })

or

const permission = BlobSASPermissions.parse('r')

Note that both parse() and from() are static methods, so you don’t need to call it with the new operator.

0reactions
ljian3377commented, Jan 25, 2021

You are welcome. Will close this issue now. Feel free to re-open it if any help is needed from us regarding it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found