I am trying to upload file and send post parameters at the same time like this:
$response = $client->post('http://example.com/api', [
'form_params' => [
'name' => 'Example name',
],
'multipart' => [
[
'name' => 'image',
'contents' => fopen('/path/to/image', 'r')
]
]
]);
However my form_params fields are ignored and only the multipart fields are present in my post body. Can I send both at all with guzzle 6.0 ?
I ran into the same problem. You need to add your form_params to the multipart array. Where 'name' is the form element name and 'contents' is the value. The example code you supplied would become:
$response = $client->post('http://example.com/api', [
'multipart' => [
[
'name' => 'image',
'contents' => fopen('/path/to/image', 'r')
],
[
'name' => 'name',
'contents' => 'Example name'
]
]
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With