Skip to content

Commit

Permalink
Merge pull request #8 from gentics/master-fix-file-upload
Browse files Browse the repository at this point in the history
fix file upload for single files
  • Loading branch information
netwarex authored Jan 25, 2022
2 parents 8267070 + efd04ad commit 0fd77c2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/MeshClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ protected function setMultipart(RequestInterface $request)
}

foreach ($_FILES as $key => $value) {
if (!is_array($value)) {
if (!is_array($value) || !empty($value['tmp_name'])) {
$value = [$value];
}

Expand All @@ -194,9 +194,16 @@ protected function setMultipart(RequestInterface $request)
}
}
}

$body = new MultipartStream($elements);

/**
* Remove any Content-Length and leverage chunked transfers for multipart-data
*/
$request = $request->withBody($body)
->withHeader('Content-Type', 'multipart/form-data; Boundary=' . $body->getBoundary());
->withoutHeader('Content-Length')
->withHeader('Content-Type', 'multipart/form-data; Boundary=' . $body->getBoundary())
->withHeader('Transfer-Encoding', 'chunked');
}

return $request;
Expand Down

0 comments on commit 0fd77c2

Please sign in to comment.