Skip to content

[HttpClient] allow upload in form to be transfer-encoded with base64 #49315

Open
@croensch

Description

@croensch

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy