Using PowerShell Invoke-RestMethod to POST large binary multipart/form-data

前端 未结 1 1957
情歌与酒
情歌与酒 2020-12-10 19:45

I\'m trying to use the Invoke-RestMethod cmdlet in PowerShell 3 and 4, to upload a large binary file using a REST API\'s multipart/form-data upload. Here is a working cURL

相关标签:
1条回答
  • 2020-12-10 20:12

    I know you asked over a year ago and probably solved the problem, but for the sake of other people who may have the same question, I'm leaving my response.

    I notice couple of mistakes in your invoke statement. First, you need to use POST keyword instead of string value. Second, make sure that Content-Type is set to multipart/form-data. So this is my revised statement -

    $uri = "http://blahblah.com"
    $imagePath = "c:/justarandompic.jpg"
    $upload= Invoke-RestMethod -Uri $uri -Method Post -InFile $imagePath -ContentType 'multipart/form-data' 
    

    You can check the response from the server by checking $upload.

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题