Unable to POST multiple multipart parameters
arjanvdbos opened this issue · comments
Arjan commented
It's seems that POST-ing multiple multipart paramaters is not possible; the GuzzleHttp\Command\Guzzle\RequestLocation\MultiPartLocation
overwrites the body for every parameter. So we end up with only the last parameter in the body.
use GuzzleHttp\Client;
use GuzzleHttp\Command\Guzzle\GuzzleClient;
use GuzzleHttp\Command\Guzzle\Description;
$client = new Client();
$description = new Description([
'baseUri' => 'http://httpbin.org/',
'operations' => [
'testing' => [
'httpMethod' => 'POST',
'uri' => '/post',
'responseModel' => 'postResponse',
'parameters' => [
'foo' => [
'type' => 'string',
'location' => 'multipart'
],
'baz' => [
'type' => 'string',
'location' => 'multipart'
]
]
]
],
'models' => [
'postResponse' => [
'type' => 'object',
'additionalProperties' => [
'location' => 'json'
]
]
]
]);
$guzzleClient = new GuzzleClient($client, $description);
$result = $guzzleClient->testing(['foo' => 'bar', 'baz' => 'qux']);
echo (string) $result;
Will result in:
GuzzleHttp\Command\Result Object
(
[args] => Array
(
)
[data] =>
[files] => Array
(
)
[form] => Array
(
[baz] => qux
)
[headers] => Array
(
[Content-Length] => 106
[Content-Type] => multipart/form-data; boundary=585a331a19fcb
[Host] => httpbin.org
[User-Agent] => GuzzleHttp/6.2.1 curl/7.49.1 PHP/7.1.0
)
[json] =>
[origin] => 127.0.0.1
[url] => http://httpbin.org/post
)
Stefano Kowalke commented
Can you try latest develop
branch. In case you want to send a file use any
as param type.
Arjan commented
Thanks man, this solves the issue!