# File upload request with form-data file : generated Powershell code does not work

**URL:** <https://community.postman.com/t/file-upload-request-with-form-data-file-generated-powershell-code-does-not-work/11791>\
**Category:** Help Hub\
**Created:** [April 7, 2020, 1:49pm UTC](https://community.postman.com/t/file-upload-request-with-form-data-file-generated-powershell-code-does-not-work/11791 "2020-04-07T13:49:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JMTeamway](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@JMTeamway](https://community.postman.com/u/JMTeamway)\
**Post date:** [April 7, 2020, 1:49pm UTC](https://community.postman.com/t/file-upload-request-with-form-data-file-generated-powershell-code-does-not-work/11791/1 "2020-04-07T13:49:42Z")

</div>

Hi all !

I’m trying to do a basic call to a REST API to upload a file.  
I have a perfectyl working example with POSTMAN ( credentials, form-data, document as File in the body ).  
If I redirect the POST to a local debug server, here is what I receive :

> POST / HTTP/1.1  
> Authorization: Basic bWNpdGhhcmVsOk5hdHVyZTE1NA==  
> User-Agent: PostmanRuntime/7.24.0  
> Accept: _/_  
> Cache-Control: no-cache  
> Postman-Token: 80e88c17-ae1d-454b-bc9a-71794caae348  
> Host: localhost:8989  
> Accept-Encoding: gzip, deflate, br  
> Connection: keep-alive  
> Content-Type: multipart/form-data; boundary=--------------------------864163748135484180452120  
> Content-Length: 409483

If I launch the generated Powershell code, I get an error from the API telling me the file is empty.  
If I redirect the POST to a local debug server, here is what I receive :

> POST / HTTP/1.1  
> Authorization: Basic bWNpdGhhcmVsOk5hdHVyZTE1NA==  
> User-Agent: Mozilla/5.0 (Windows NT; Windows NT 10.0; fr-FR) WindowsPowerShell/5.1.18362.628  
> Content-Type: application/x-www-form-urlencoded  
> Host: localhost:8989  
> Content-Length: 0  
> Connection: Keep-Alive

I notice at first sight that the content-type is **application/x-www-form-urlencoded** instead of **multipart/form-data**.

Here is the sample code generated :

> ```
> $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
> $headers.Add("Authorization", "Basic bWNpdGhhcmVsOk5hdHVyZTE1NA==")
> 
> $multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
> $multipartFile = '/L:/TBD_CGVWorkplaceTeamWay.pdf'
> $FileStream = [System.IO.FileStream]::new($multipartFile, [System.IO.FileMode]::Open)
> $fileHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
> $fileHeader.Name = "file"
> $fileHeader.FileName = "/L:/TBD_CGVWorkplaceTeamWay.pdf"
> $fileContent = [System.Net.Http.StreamContent]::new($FileStream)
> $fileContent.Headers.ContentDisposition = $fileHeader
> $multipartContent.Add($fileContent)
> 
> $body = $multipartContent
> 
> $response = Invoke-RestMethod 'http://localhost:8989' -Method 'POST' -Headers $headers -Body $body
> $response | ConvertTo-Json
> 
> ```

Any idea to help me fix that code ?
