My Powershell 7 script reads JPG files from a content service.
$fetch = @{
Uri = 'https://content.site/media?id=82348'
Method = GET
}
$fetchResponse = Invoke-WebRequest @fetch
Image data loads into $fetchResponse.content
as a byte array. Now I must send to a local web server.
$ingest = @{
Uri = 'https:\\internal.site\ingest'
Method = POST
Form = @{
file = $fetchResponse.content
id = '82348'
}
}
$ingestResponse = Invoke-WebRequest @ingest
Sending the byte array directly as above does not work. Image data is not detected in the received form.
If I first save the image locally and then use Get-Item to point to the file, it is successful. I do not want to save the images locally if avoidable.
Does the byte array need to be converted to another format to use the form parameter in Invoke-WebRequest?
Edit: after a bit of circular questioning and answering in the comments, maybe the question is better asked as, "How do I convert a variable's byte array to System.IO.FileInfo without having to write a file to disk?"