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 name
  • contents: (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.
1. $client->request('POST', '/post', [
2. 'multipart' => [
3. [
4. 'name'     => 'foo',
5. 'contents' => 'data',
6. 'headers'  => ['X-Baz' => 'bar']
7. ],
8. [
9. 'name'     => 'baz',
10. 'contents' => fopen('/path/to/file', 'r')
11. ],
12. [
13. 'name'     => 'qux',
14. 'contents' => fopen('/path/to/file', 'r'),
15. 'filename' => 'custom_filename.txt'
16. ],
17. ]
18. ]);

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-urlencodedrequests, and multipart for multipart/form-data requests.

This option cannot be used with body, form_params, or json