# Cannot upload a file through the API with the synchronous parameter

**URL:** <https://meta.discourse.org/t/cannot-upload-a-file-through-the-api-with-the-synchronous-parameter/43799>\
**Category:** Development\
**Tags:** rest-api\
**Created:** [6. Mai 2016 um 14:33 UTC](https://meta.discourse.org/t/cannot-upload-a-file-through-the-api-with-the-synchronous-parameter/43799 "2016-05-06T14:33:05Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![PeterWells](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@PeterWells](https://meta.discourse.org/u/PeterWells)\
**Post date:** [6. Mai 2016 um 15:11 UTC](https://meta.discourse.org/t/cannot-upload-a-file-through-the-api-with-the-synchronous-parameter/43799/3 "2016-05-06T15:11:40Z")

</div>

The code looks like this:

```
$contentType=$r.BaseResponse.ContentType
$content=Get-Content $fileOut
$boundary=[system.Guid]::NewGuid().ToString()
$clientID=[system.Guid]::NewGuid().ToString()
$body=(
"--$boundary",
'Content-Disposition: form-data; name="type"',
'',
"image",
"--$boundary",
"Content-Disposition: form-data; name=""files[]"" filename=$imageName",
"Content-Type: ""$contentType""",
'',
"$content",
"--$boundary--"
) -join "`r`n"
$tempURL=$urlTo+"uploads.json"+$loginTo+"&client_id=$clientID&synchronous=1"
$resp=Invoke-WebRequest $tempURL -Method Post -ContentType "multipart/form-data; boundary=$boundary" -Body $body -Verbose

```

$urlTo is the url for the site, $loginTo is the APIkey and username. The $r at the top is the response from downloading the image from another site to a file called $fileOut

---

_[View the full topic](https://meta.discourse.org/t/cannot-upload-a-file-through-the-api-with-the-synchronous-parameter/43799)._
