Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpClient] multipart/form-data request issue with file name #36738

Copy link
Copy link
Closed
@ghostika

Description

@ghostika
Issue body actions

Symfony version(s) affected: 5.0.7

Description
I have 2 basic SF projects, one is a fileupload microservice and an admin interface for the users. The workflow is that the user first uploads the file in the admin interface and then it makes a post request internally to the microservice.
After some debugging, I realized the problem is with the name of the file.

How to reproduce
The upload controller in the MC is a simple Symfony controller.

public function upload(Request $request)
{
    $uploadedFile = $this->request->files->get('file');
    ....
}

If I call this endpoint with the HTTP client and with a specified filename, the $uploadedFile is null.

The post request with the HTTP client is the same as the example in the Symfony documentation.

public function upload(string $filePath, string $originalFilename): ?string
    {
        $formFields = [
            'file' => DataPart::fromPath($filePath, $originalFilename),
        ];
        $formData = new FormDataPart($formFields);

        $options = [
            'headers' => $formData->getPreparedHeaders()->toArray(),
            'body' => $formData->bodyToIterable(),
        ];

        $response = $this->client->request('POST', self::RESOURCE_PATH, $options);

If the originalFilename is a uuid or it's not specified, everything is ok.

Possible Solution
I can only assume, that the problem is in the HTTP client, but I have no idea where to search for it.

Additional context

Headers:

Content-Disposition: form-data; name=file; filename=58a21f90-ae95-4758-b72b-45f14eddf62d.jpeg

But if I have the original file with the filename: Canon EOS 5DS R (8688 × 5792).JPG

Content-Disposition: form-data; name=file; filename*=utf-8''Canon%20EOS%205DS%20R%20%288688%E2%80%8A%C3%97%E2%80%8A5792%29.JPG

In this case, the $_FILE global variable is simply empty.

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.