Upload File to Azure Blob Storage with PowerShell

Raygadas Dominguez, Daniela 21 Reputation points
2021-02-02T04:27:35.017+00:00

Hello,

I am trying to upload a file to Azure Blob Storage with PowerShell by using the native REST API and a SAS Token.

I generated the SAS through my Azure Portal and I did it by first creating an access policy at the container level and then creating the SAS using that access policy. The SAS I created was for the container level, as I want to upload blobs to this container.

I am following this guys example: https://rzander.azurewebsites.net/upload-file-to-azure-blob-storage-with-powershell/ but I did not need the part where he is using the $name in the URL.

And I am getting the following error:

Invoke-RestMethod : AuthenticationFailedServer failed to authenticate the request. Make sure the value of Authorization
header is formed correctly including the signature.
RequestId:XXXXXXXXXXXXXXXXXXXXX
Time:2021-02-02T04:08:50.5626777ZSignature did not match. String to sign used was

At XXXXXXXXXXXXXXXX

  • Invoke-RestMethod -Uri $uri -Method Put -Headers $headers -InFile $fi ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExceptio
    n
  • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I read that since I am using the SAS Token I do not need the Authorization header

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,219 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,916 questions
{count} votes

Accepted answer
  1. Sumarigo-MSFT 46,441 Reputation points Microsoft Employee
    2021-02-02T07:52:54.397+00:00

    @Raygadas Dominguez, Daniela Welcome to Microsoft Q&A, Thank you for posting your query!

    Can you try to re-generate the SAS token through Azure Storage Explorer tool or generating a shared access signature (in azure portal) for key2 instead of key1. Changing the key fixed the error. (Settings > Shared access signature) Also the connection string should be updated as well - if used. (Settings > Access keys)and try again

    Also to upload or download files to an Azure Storage account, there are several option, Especially easy and the fastest ways is through Azcopy tool

    Some time PC time could cause this issue, please check the date and time.

    Authorize requests to Azure Storage

    Additional information: PowerShell Basics: How to Upload Files to Azure Storage

    Hope this helps!

    Kindly let us know if the above helps or you need further assistance on this issue.

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

    Please don’t forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.