Azure / Azure/azure-rest-api-specs
Unable to update block blob in Azure Storage Account using REST API
- Dominant language
- TypeSpec
- Stars
- 3.1k
- Forks
- 5.9k
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 444
Description
Hi, I am trying to update the content of a block blob using the storage key and a call to the Azure REST API but it fails stating the body length in my call is wrong.
Call:
$AccountName = "Storage account name"
$Sig = "Key of the storage account"
$container = "Name of the container"
$FileName = "Name of the block blob to update"
$Body = "Contains the text that I want to place inside the block blob"
$authhdr = "SharedKey $AccountName`:$sig"
$datestr=((Get-Date).ToUniversalTime()).ToString("R")
$RequestHeader = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$RequestHeader.Add("Authorization", $authhdr)
$RequestHeader.Add("Content-Type", "text/plain; charset=UTF-8")
$RequestHeader.Add("x-ms-date", $datestr)
$RequestHeader.Add("x-ms-version", "2015-04-05")
$RequestHeader.Add("x-ms-blob-type","BlockBlob")
$RequestHeader.Add("Content-Length",$Body.Length)
Invoke-RestMethod -Method Put -Uri "https://$AccountName.blob.core.windows.net/$container/$FileName" -Body $Body -Headers $RequestHeader -SkipHeaderValidation
Result:
Invoke-RestMethod:
Bad Request
Bad Request - Invalid Content Length
HTTP Error 400. There is an invalid content length or chunk length in the request.
Expected result:
The block blob is update with the content of the $Body variable.
This was working fine about 2 months ago, I was able to test it and now I get this problem about the size of the body.
Does anyone have the same problem?
Thank you!
Contributor guide
Research direction
No repository file or test is identified. Start with the PowerShell Invoke-RestMethod PUT call and the Azure Blob Storage REST API request details; reproduce the invalid content-length response and determine what request behavior is expected for the block blob update.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, powershell
- Domain
- api, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100