Product: PowerShell Universal
Version: 3.4.4
Is there another accepted method of FileUpload a part from -infile?
I am trying to utilise an enpoint to perform a few functions as well as upload a file to seperate service.
When using Invoke-RestMethod -Infile, I can no longer specificy -Body.
Is there a method I can use to specifiy Parameters or include the filecontents in the Body?
I tried using multipart forms which allow me to upload.
$fileBin = [System.IO.File]::ReadAlltext($filePath)
$boundary = [System.Guid]::NewGuid().ToString()
$LF = "`r`n"
$bodyLines = (
"--$boundary",
"Content-Disposition: form-data; name=`"file`"; filename=`"$fileName`"",
"Content-Type: application/octet-stream$LF",
$fileBin,
"--$boundary--$LF"
) -join $LF
Invoke-RestMethod -Uri $uri -Method Post -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines
but as soon as I trry and add in a param block into the script and add that field in, it gives an erro 400
$fileBin = [System.IO.File]::ReadAlltext($filePath)
$boundary = [System.Guid]::NewGuid().ToString()
$LF = "`r`n"
$bodyLines = (
"--$boundary",
"Content-Disposition: form-data; name=`"Name`"$LF",
"test",
"--$boundary",
"Content-Disposition: form-data; name=`"file`"; filename=`"$fileName`"",
"Content-Type: application/octet-stream$LF",
$fileBin,
"--$boundary--$LF"
) -join $LF
Invoke-RestMethod -Uri $uri -Method Post -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines
Testing with a simple Endpoint
param($Name)
$Name
[IO.File]::WriteAllBytes("C:\temp\tempfile.dat", $Data)