multipart
- Summary
- Sets the body of the request to a multipart/form-data form.
- Types
- array
- Constant
GuzzleHttp\RequestOptions::MULTIPART
The value of
multipart
is an array of associative arrays, each containingthe following key value pairs:
name
: (string, required) the form field namecontents
: (StreamInterface/resource/string, required) The data to use inthe form element.headers
: (array) Optional associative array of custom headers to use withthe form element.filename
: (string) Optional string to send as the filename in the part.
- $client->request('POST', '/post', [
- 'multipart' => [
- [
- 'name' => 'foo',
- 'contents' => 'data',
- 'headers' => ['X-Baz' => 'bar']
- ],
- [
- 'name' => 'baz',
- 'contents' => fopen('/path/to/file', 'r')
- ],
- [
- 'name' => 'qux',
- 'contents' => fopen('/path/to/file', 'r'),
- 'filename' => 'custom_filename.txt'
- ],
- ]
- ]);
Note
multipart
cannot be used with the form_params
option. You will need touse one or the other. Use form_params
for application/x-www-form-urlencoded
requests, and multipart
for multipart/form-data
requests.
This option cannot be used with body
, form_params
, or json