0

I am trying to upload a blob to azure storage account using REST API.

As read in many docs, I am first creating the file:

$headers = @{ 'x-ms-blob-type' = 'BlockBlob' } 

Invoking PUT operation to the SAS URI (directly copied from Azure portal)

https://mystorage.blob.core.windows.net/pdf/agb_megasim.pdf?sp=rac&st=2021-06-30T09:52:08Z&se=2021-07-31T17:52:08Z&spr=https&sv=2020-02-10&sr=c&sig=uhuEFp%2Bl1MJO%2B8dfsUYkfpegPK9KeYPOPsN08govKGg%3D 

Next, I am sending (PUT) a byte stream to the url. The SAS url is modified to add comp=range

$headers = @{ "x-ms-version" = "2015-02-21" "x-ms-range" = "bytes=0-86751" "x-ms-date" = "7/5/2021 4:55:47 PM" "x-ms-write" = "update" 'x-ms-blob-type' = 'BlockBlob' } 
https://mystorage.blob.core.windows.net/pdf/agb_megasim.pdf?**comp=range**&sp=rac&st=2021-06-30T09:52:08Z&se=2021-07-31T17:52:08Z&spr=https&sv=2020-02-10&sr=c&sig=uhuEFp%2Bl1MJO%2B8dfsUYkfpegPK9KeYPOPsN08govKGg%3D 
<?xml version="1.0" encoding="utf-8"?> <Error> <Code>InvalidQueryParameterValue</Code> <Message>Value for one of the query parameters specified in the request URI is invalid. RequestId:bd905701-d01e-0036-6fbc-71bbbf000000 Time:2021-07-05T16:42:26.9354872Z</Message> </Error> 

This seems to be the procedure from various documents I tried, but doesnt work for me! I tried using Powershell and postman.

Any idea which parameter is causing the issue?

Also, this is how i intend to pass the file contents: Reading the file

$fileContentBytes = [System.IO.File]::ReadAllBytes($file) 

Not sure, if encoding is required,

[System.Convert]::ToBase64String($fileContentBytes) 

1 Answer 1

1

Considering you're performing Put Blob operation and trying to create a Block Blob, you need not specify comp=range parameter in your query string. Please try your operation by removing that.

Furthermore, the only header you need to provide in your request is x-ms-blob-type. You can remove all other headers from your request.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, the doc said many of these were required. learn.microsoft.com/en-us/rest/api/storageservices/put-blob It was a mistake trying to follow steps used for azure files :( I have tried this as just one PUT operation and it works!
the doc said many of these were required - They are required when you're authorizing your requests using shared key authorization (i.e. using account key). Since you're using a shared access signature, most of these headers are not required.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.