Description
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.