Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
croensch opened this issue Feb 9, 2023 · 6 comments · May be fixed by #49587
Open

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

croensch opened this issue Feb 9, 2023 · 6 comments · May be fixed by #49587

Comments

@croensch
Copy link

croensch commented Feb 9, 2023

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.

@nicolas-grekas
Copy link
Member

Would you consider a PR to the Mime component, to allow your use case?

@croensch croensch linked a pull request Mar 2, 2023 that will close this issue
@croensch
Copy link
Author

croensch commented Mar 3, 2023

I'm trying but it's hard to work around that internal design >_<
I've tried a different route but that's even more broken:
6.3...croensch:symfony:mime-49315-fubar

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@carsonbot
Copy link

Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

@javiereguiluz
Copy link
Member

Reopening because the related PR #49587 is still open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants