Post to API users.setAvatar gives "Unexpected end of form"

I need some help to set an avatar on a user with Powershell. First, it works with curl on windows but I need to understand why it is failing with Powershell and Invoke-WebRequest/Invoke-RestMethod.
Curl that Works:
curl -H “X-Auth-Token: x” -H “X-User-Id: x” -F “image=@C:.…\1px.png” -F “username=magard” http://host:3000/api/v1/users.setAvatar

The closest I can get with Powershell is:

$uri = “x:3000/api/v1/users.setAvatar”
$file = Get-Item “C:..\1px.png”
$fileName = $file.Name
$fileBytes = [System.IO.File]::ReadAllBytes($file);
$fileiso = [System.Text.Encoding]::GetEncoding(‘iso-8859-1’).GetString($fileBytes);
$boundary = [System.Guid]::NewGuid().ToString()
$LF = “`n”

$bodyLines = (
“Content-Disposition: form-data; name="image”; filename="$($fileName)“”,
‘Content-Type: image/png’,
‘Content-Disposition: form-data; name=“username”’,
) -join $LF

$result = Invoke-WebRequest -Uri $uri -Method Post -ContentType “multipart/form-data; boundary=------------------------$boundary” -SkipHeaderValidation -UseBasicParsing -Body $bodyLines -Headers $headers -UserAgent “curl/8.4.0”

A wireshark trace and compare between the two Posts shows that they are identical , I even set the user-agent as curl… :

What am I missing here ? please help :smiley:

Replying to my own question since I solved part of the problem…
As you probably noted the Content-Length was not the same in the compare, that made me try another way to set the newline. Changeing to :
$LF = [System.Environment]::NewLine
made this way to post work.