I\'m currently trying to upload a file to a Webserver by using a REST API. And as mentioned I\'m using PowerShell for this. With curl this is no problem. The call looks like
I had some troubles trying to do the following curl
command using Invoke-RestMethod:
curl --request POST \
--url https://example.com/upload_endpoint/ \
--header 'content-type: multipart/form-data' \
--form 'file=@example.csv'
-v
In my case, it turned out to be much easier to just use curl
directly inside powershell.
$FilePath = "C:\example.csv"
$CurlExecutable = "C:\curl-7.54.1-win64-mingw\bin\curl.exe"
$CurlArguments = '--request', 'POST',
'https://example.com/upload_endpoint/',
'--header', "'content-type: multipart/form-data'",
'--form', "file=@$FilePath"
'-v',
# Debug the above variables to see what's going to be executed
Write-Host "FilePath" $FilePath
Write-Host "CurlExecutable" $FilePath
Write-Host "CurlArguments" $CurlArguments
# Execute the curl command with its arguments
& $CurlExecutable @CurlArguments
Just grab the executable for your os on curl's website.
curl
instead of powershell's invoke-restmethod
?