Send Image Attachment to PushOver

Using the PushOver app ( I can easily send a message with powershell. It supports adding image attachments but this part I haven’t been able to figure out.

$uri = ""

$parameters = @{
token = "myapptoken"
user = "myusertoken"
message = "the message"
title = "the title"

Invoke-RestMethod -Uri $uri -Method Post -Body $parameters

That will cause the message to appear on my phone.

However if I look at their FAQs (Pushover: API)

It says I need to do the following:

[other HTTP headers]
Content-Type: multipart/form-data; boundary=--abcdefg

Content-Disposition: form-data; name="user"

[ your Pushover user key ]
Content-Disposition: form-data; name="token"

[ your Pushover API token ]
Content-Disposition: form-data; name="message"

your message here
Content-Disposition: form-data; name="attachment"; filename="your_image.jpg"
Content-Type: image/jpeg

[ raw binary data of image file here ]

I’ve tried various solution from bing’ing rest uploads, but none work. I always get 400 bad request.

Most recently I tried this with no luck:

$FilePath = 'c:\users\stephen\pictures\mypic.jpg';
$Uri = '';

function AddData{
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = $Name
$StringContent = [System.Net.Http.StringContent]::new($Value)
$StringContent.Headers.ContentDisposition = $stringHeader

return $StringContent

$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()

$multipartContent.Add((AddData -Name "token" -Value "token"))
$multipartContent.Add((AddData -Name "user" -Value "usertoken"))
$multipartContent.Add((AddData -Name "message" -Value "the message"))
$multipartContent.Add((AddData -Name "title" -Value "the title"))

$multipartFile = $FilePath
$FileStream = [System.IO.FileStream]::new($multipartFile, [System.IO.FileMode]::Open)
$fileHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$fileHeader.Name = "attachment"
$fileHeader.FileName = 'Jay_Small.jpg'
$fileContent = [System.Net.Http.StreamContent]::new($FileStream)
$fileContent.Headers.ContentDisposition = $fileHeader
$fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("image/jpg")

Invoke-WebRequest -Uri $uri -Body $multipartContent -Method 'POST' #-ContentType "multipart/form-data;"

So, the difficulty here is that you’re really doing low-level .NET programming, just as someone would do in C#. This isn’t “PowerShell” per se; you might have better luck asking on a dev-centric site like Even if you found a working example in C#, it’d be easy to translate that into PowerShell, if that’s what you need to do.