0

I am trying to create a sas token from react app

async function GenerateSASToken() {
    const sasUrl = `https://${accountname}.blob.core.windows.net?sv=2021-06-08&ss=bfqt&srt=sco&sp=rwdlacupiytfx&se=2023-02-20T16:01:34Z&st=2023-02-20T08:01:34Z&spr=https&sig=<signinkey>`;
    axios.get(sasUrl)
        .then(response => {
            console.log(response.data);
            console.log('SUCCESS');
        })
        .catch(error => {
            console.log('FAIL');
            console.error(error);
        });
}

But I am getting error while calling endpoint as

400 (Value for one of the query parameters specified in the request URI is invalid.)

Imgane5h
  • 304
  • 1
  • 3
  • 16

1 Answers1

0

The reason you are getting this error is because you are using incorrect URL.

If you want to download a blob, the URL should be something like https://${accountname}.blob.core.windows.net/<container-name>/<blob-name>?sv=2021-06-08&ss=bfqt&srt=sco&sp=rwdlacupiytfx&se=2023-02-20T16:01:34Z&st=2023-02-20T08:01:34Z&spr=https&sig=<signinkey>.

The URL you are using corresponds to Get Account Information which requires restype=account&comp=properties URL parameters. Since you are not including these parameters in your URL, you are getting 400 error.

UPDATE

If you are trying to generate a new SAS token, please note that:

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • Ok Thanks @Gaurav but my scenario is, I have UI which downloads blob. I have completed code to download blob using SAS token (which I generated from portal) like https://${STORAGE_ACCOUNT_NAME}.blob.core.windows.net${SAS_TOKEN} But here instead of getting token from portal and updating it in code everytime it expires is not a solution so i want to generate sas token programmatically. How can I do it? – Imgane5h Feb 20 '23 at 12:25
  • In this case you would need an API endpoint which will return you a SAS token. You will then need to use SAS token to download the blob. – Gaurav Mantri Feb 20 '23 at 12:30
  • Ok But How will API generate sas token? – Imgane5h Feb 20 '23 at 12:35
  • You can use Azure Storage SDK in your API code to generate the token. – Gaurav Mantri Feb 20 '23 at 12:47