0

I am trying to retrieve a file(File type: csv or xml) by REST API from Azure File Storage, I have Storage Account Name & Key

e.g. account: testgetfilestorage PW:ABC/abc82abc93f80+YCKJH23YGOabcabcabcabcbacbabcbabcabcbabcabcbacmZQ==

I use the "Microsoft Azure Storage Explorer" tool can view & download files successfully, but I test it on Postman was not successful, there is an error: view error image

----------------------------------

Following is my setting on Postman


In Header:

x-ms-version: 2014-02-14


In URL:

GET https://testgetfilestorage.file.core.windows.net/integration/TestFile.xml

I can 100% sure the file exists on File Shares, but the error return 404. May I know anything I did wrong? Thanks

Jack
  • 3
  • 2
  • Welcome to Stack Overflow. While I understand your account name and key are for a test file, it's still not a good idea to include your credentials in your post. How are you setting up postman to download the file? – ewokx Jun 28 '22 at 02:59
  • I have rewritten the account and PW to fake, so it is safe to show an example. – Jack Jun 28 '22 at 03:06

1 Answers1

0

All requests to Azure File Storage must be authorized. The reason you are getting the 404 error is because the requests are not authorized.

If you are using account name/key, you have two options:

  1. Create Authorization header and include Authorization header in your request. Steps to compute authorization header is described here: https://learn.microsoft.com/en-us/rest/api/storageservices/authorize-with-shared-key.

  2. Use Shared Access Signature. Instead of using authorization header, you can create a Shared Access Signature (SAS) token on the file and use that SAS token as part of the request URL. Steps to compute SAS token for a storage resource is described here: https://learn.microsoft.com/en-us/rest/api/storageservices/create-service-sas. You can also create a SAS token on the file using Storage Explorer or Azure Portal. When creating SAS token, please ensure that it has at least read permission.

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • Thanks for your reply, I followed your suggestion 1. to add an Authorization header in the API call, but it shows another error which is" AuthenticationFailed Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:b2f8bd70-xxxx-xxxx-xxxx-xxxx49000000 Time:2022-06-28T06:28:01.8264626Z" – Jack Jun 28 '22 at 06:38
  • I have added in header ---> "x-ms-date:Tue, 28 Jun 2022 06:20:00 GMT" & "Authorization:SharedKey testgetfilestorage:ABC/abc82abc93f80+YCKJH23YGOabcabcabcabcbacbabcbabcabcbabcabcbacmZQ==" – Jack Jun 28 '22 at 06:58
  • You simply can't add your account key as authorization header. Please see this [link](https://learn.microsoft.com/en-us/rest/api/storageservices/authorize-with-shared-key) regarding instructions to compute it. – Gaurav Mantri Jun 28 '22 at 07:18
  • Thank you for your help Gaurav, I think you have answered my question in this post. I have opened another further question on the other post since it is more suitable to separate the question in order to keep it clear for people to understand, I would be grateful if you could also take a look at another post, thanks https://stackoverflow.com/questions/72810548/signature-authentication-failed-when-call-api-to-azure-file-storage – Jack Jun 30 '22 at 07:00