postmanlabs / postmanlabs/postman-code-generators

Code generator for Powershell v5

Open
#501 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

codegen
Dominant language
JavaScript
Stars
1k
Forks
381
PR merge metrics
No merged PRs in 30d

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the generated multipart upload in PowerShell v5 using the example in the issue, then compare its behavior with PowerShell v7. Done means the generated script sends the file and form-data key-values to the stated upload endpoint and the server receives them.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, powershell
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.