0

I'm trying to upload a file on an API using RESTAPI method and using powershell task in Azure DevOps. I'm able to upload the file but still there is some issue with the file. I'm now trying to upload this file as a binary file on that API but I'm not getting how to upoad the file as a binary. While using curl , we have an option --data-binary but how can we use this option in powershell method. Please guide. Below is the code:

$Url = 'https://example.com/FileUploadSet'
$Path = 'D:\a\r1\a/_ci/drop/s/test.mtar'
$Body = @{
    "path" = "$Path"
} | ConvertTo-Json

$headers = @{
    'ContentType' = 'application/octet-stream'
    'Accept' = '*/*'
    'APIKey' = $env:API
}
curl -Uri $Url -Method Post -body $Body -Headers $headers
gaurav sharma
  • 91
  • 1
  • 10
  • Have you tried parameter `-InFile`? https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.2#-infile – zett42 Nov 04 '22 at 10:00
  • Thanks @zett42 .. it worked after adding the -InFile option .. kindly post it as an answer. – gaurav sharma Nov 04 '22 at 18:07

0 Answers0