guzzle / psr7

PSR-7 HTTP message library
MIT License
7.88k stars 3 forks source link

Accepts nested array in multipart option field value #616

Open RomainMazB opened 1 month ago

RomainMazB commented 1 month ago

This PR expands a MultipartStream element with a nested array contents into multiple separated and well-formed elements.

Basically, this:

[
  'name' => 'foo',
  'contents' => [
    ['key' => 'bar'],
    ['key' => 'baz']
  ]
]

results into this:

--boundary
Content-Disposition: form-data; name=foo[0][key]
Content-Length: 3

bar
--boundary
Content-Disposition: form-data; name=foo[1][key]
Content-Length: 3

baz
--boundary--

This is an attempt to ease the DX for Guzzle, see https://github.com/guzzle/guzzle/issues/3260