Open
Description
Description
I wanted to use HttpClient to upload a file alongside other fields. But i needed the file uploading part to be Content-Transfer-Encoding: base64
*. When i followed the docs https://symfony.com/doc/current/http_client.html#uploading-data i could see that my data-part starts out with encoding base64. But when added to a form it is forced to be 8bit / binary. See:
https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/Mime/Part/Multipart/FormDataPart.php#L105
I don't know if the transfer encoding is allowed by MIME but NodeJS Multiparty seems to understand it.
- because AWS API Gateway breaks binary uploads via Lambda
Example
$dataPart = DataPart::fromPath($pathToPdf, 'foo_bar.pdf', 'application/pdf');
$multipartFormData = new FormDataPart([
'foo' => "Foo",
'bar' => "Bar",
'attachment' => clone $dataPart
]);
$formDataParts = $multipartFormData->getParts();
array_pop($formDataParts); // attachment
$formDataParts[] = $dataPart;
$multipartMixed = new MixedPart(...$formDataParts);
$response = $this->myApiClient->request('POST', 'send', [
'headers' => $multipartFormData->getPreparedHeaders()->toArray(),
'body' => $multipartMixed->bodyToIterable()
]);
This does not work because the new mixed part generates a new random boundary.