Description
Symfony version(s) affected: 4.4.3
Description
I'm communicating with an API and ran in some problems when I tried to upload files with the HTTPClient.
How to reproduce
Unfortunately it's not a public API so i can't provide the exact examples but i'm basically doing what's described in the docs:
$fields = [
'file' => new DataPart($csv, 'test.csv', 'text/csv'),
];
$formData = new FormDataPart($fields);
$httpClient->request('POST', '/', ['body' => $formData->bodyToString()]);
Possible Solution
The problem is because in the data part the content-type has an additional token name=file
(see below). At least if i remove it from the request everything works fine. I was looking in the rfc7233 and rfc7578 spec but couldn't really find anything about this, but not sure if i'm just missing it or looking in the wrong spec.
--_=_symfony_1579722514_dac69a39ca05c454f2a6375249ce7614_=_
Content-Type: text/csv; name=file
Content-Transfer-Encoding: 8bit
Content-Disposition: form-data; name=file; filename=test.csv
.... data ...
--_=_symfony_1579722514_dac69a39ca05c454f2a6375249ce7614_=_--
The second issue I ran into was that the boundary in the request headers is enclosed in quotes, which also causes propblems. Again, couldn't really find something about that but it's not in the request when i'm just using curl in the terminal.
Doesn't work:
Content-Type: multipart/form-data; boundary="_=_symfony_1579723754_2b148207ef318a96c271a8e5bd56b206_=_"
Works:
Content-Type: multipart/form-data; boundary=_=_symfony_1579723754_2b148207ef318a96c271a8e5bd56b206_=_
Are these problems in the symfony mime client or in the API i'm working with?