Media/upload doesn't work (powershell)

api
powershell

#1

I’m trying to upload an image (jpg, 32kb) to Twitter, to embedd it in a tweet afterwards. But I’m still getting the following error:

Invoke-RestMethod : {"errors":[{"code":38,"message":"media parameter is missing."}]}

Here is the image-generation:

$image = [System.IO.File]::ReadAllBytes("C:\tools\webflow_RepostTwitter\ISR_LOGO_3155_pantone.jpg")#Invoke-Webrequest "https://res.cloudinary.com/isr-de/image/upload/t_posts-thumbnail/v1504271631/posts/platform.jpg"
$image = [System.Convert]::ToBase64String($image)

And here is the actual body-generation:

$contents = New-Object System.Text.StringBuilder

$boundary = [System.Guid]::NewGuid().ToString()
$header = "--{0}" -f $boundary
$footer = "--{0}--" -f $boundary

[void]$contents.AppendLine($header);
[void]$contents.AppendLine()
[void]$contents.AppendLine("Content-Disposition: form-data;name=""media"";filename=""platform.jpg""")
[void]$contents.AppendLine("Content-Type: image/jpeg")
[void]$contents.AppendLine("Content-Transfer-Encoding: base64")
[void]$contents.AppendLine()
[void]$contents.AppendLine($paramList.Item("media_data"))
[void]$contents.AppendLine()
[void]$contents.AppendLine($footer)
$z =  $contents.ToString()

echo $z

$postParamsBody = @{"media_data"="$z"}
$postParamsHeader = @{"Authorization"="$authorization";"Content-Type"="multipart/form-data;boundary=$boundary"}

Invoke-RestMethod -Uri $url -Method Post -Headers $postParamsHeader -Body $postParamsBody

The body looks exactly like that (from echo $z above):

--809dd84c-4ddf-405f-880d-2dcc7c5ae6b5

Content-Disposition: form-data;name="media";filename="platform.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: base64

"base64-encoded image-data" (left out for better readability)

--809dd84c-4ddf-405f-880d-2dcc7c5ae6b5--

Creating new Tweets already works without problems.
I would appreciate some suggestions and thanks for every help!