如何将curl文件上传命令转换为Invoke-RestMethod?

时间:2020-01-20 22:00:06

标签: powershell rest curl

我想转换以下命令:

$ curl -X POST \
-H 'Content-Type: multipart/form-data' \
-H "Session-Token: [Session Token]" \
-H "App-Token: [MyToken] " \
-F 'uploadManifest={"input": {"name": "Uploaded document", "_filename" : ["file.txt"]}};type=application/json' \
-F 'filename[0]=@file.txt' \
'http://path/to/glpi/apirest.php/Document/'

使用Invoke-RestMethod命令。 我遵循得出以下结果,但无法理解如何将这部分传递给此:

"-F 'uploadManifest={"input": {"name": "Uploaded document", "_filename" : ["file.txt"]}};type=application/json' \"

我的结果:

$header = @{} ;
$header['Session-Token'] = $session
$header['App-Token'] = $apptoken
$header['Accept'] = "application/json"
$header['Content-Type'] = "multipart/form-data"

$body_input = @{}
$body_input["name"] = "My Document"
$body_input["_filename"] = "MyDoc.txt"

$InputObjectTab = @{} ;
$InputObjectTab."input" = $body_input ;
$JsonItem = ConvertTo-Json $InputObjectTab

$FilePath = "‪C:\Users\MyUser\Downloads\test.txt" ;
$uri = "$GlpiUri/apirest.php/Document"
$GlpiDocument      = Invoke-RestMethod -uri $uri -Method Post  -Headers $header -ContentType 'image/jpg' -InFile $FilePath

您了解,该命令允许您使用REST API上传文件

有什么想法吗?

0 个答案:

没有答案