Everything looks fine (I edited the file path correctly and added System.Net.http). However on the server side I don't get any key-values or files.
After searching on google I found a workaround that is to use powershell v7. However, this version is not universal and requires additional installation.
So can you guys show me how to write a script that works with powershell v5? Or if possible, I think you guys should make postman-code-generators work with powershell v5.
Thank you very much!
Same problem here. I found that the key of the file is not sending properly. To the API is sent "System_Net_Http_StreamContent\":null, but it should be "file".
I am trying to upload a file with powershell. To do this I used Postman (form-data) to generate a powershell script like this:
add-type -AssemblyName System.Net.Http $multipartContent = [System.Net.Http.MultipartFormDataContent]::new() $multipartFile = 'C:\Users\hoang\Desktop\ntdll.h' $FileStream = [System.IO.FileStream]::new($multipartFile, [System.IO.FileMode]::Open) $fileHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data") $fileHeader.Name = "file" $fileHeader.FileName = "/C:/Users/hoang/Desktop/ntdll.h" $fileContent = [System.Net.Http.StreamContent]::new($FileStream) $fileContent.Headers.ContentDisposition = $fileHeader $multipartContent.Add($fileContent)
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data") $stringHeader.Name = "bla" $stringContent = [System.Net.Http.StringContent]::new("this is test") $stringContent.Headers.ContentDisposition = $stringHeader $multipartContent.Add($stringContent)
$body = $multipartContent
$response = Invoke-RestMethod '172.19.183.247:5679/api/v1/upload' -Method 'POST' -Headers $headers -Body $body $response | ConvertTo-Json
Everything looks fine (I edited the file path correctly and added System.Net.http). However on the server side I don't get any key-values or files. After searching on google I found a workaround that is to use powershell v7. However, this version is not universal and requires additional installation. So can you guys show me how to write a script that works with powershell v5? Or if possible, I think you guys should make postman-code-generators work with powershell v5. Thank you very much!