Symfony2 - File upload and "Rollback of filename must contain only ASCII characters". mistake

Using Symfony 2.5 here, users upload MS Office files to our application and upload them later as needed. Now when the file attachment contains non-ascii characters (which is quite common since we are from Czech Republic) Symfony throws the error "File rollback must contain only ASCII characters."

I found many posts about this issue and discussions, eg.

https://github.com/symfony/symfony/issues/9093

... but there is no real solution. I know I can convert the filename to ascci when creating the Content-Disposition header, but it changes the filename presented to the user, which is not very nice and quite misleading for the user. Is there a way to avoid this and be able to serve the old filename? The ability to upload a file with non-ascii characters in the filename is fairly common on the web, so why is this a limitation?

Following this How to encode Content-Disposition header name parameter in HTTP? I even tried to encode the filename with urlencode (), but now it says% is not allowed char: --(

Update 1: Here is the code snippet that I am using. I'm using streaming browser response and the headers are pretty hand-defined in my opinion.

$response = new StreamedResponse();
$response->headers->set('Content-Type', $upload->getMimeType());
$contentDisposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $upload->getFilename());
$response->headers->set('Content-Disposition', $contentDisposition);

      

+4


source to share


1 answer


Symfony 4 has $filenameFallback

a HeaderUtils::makeDisposition

.

example



$filenameFallback = preg_replace('#^.*\.#', md5($filename) . '.', $filename);
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename, $filenameFallback);
$response->headers->set('Content-Disposition', $disposition);

      

0


source







All Articles