Details
-
Bug
-
Resolution: Fixed
-
High
-
5.4.10
-
None
Description
When using BinaryStreamResponse for file downloading, it generates a fatal error for files with non-ASCII characters. Here is an excerpt from logs:
[2017-09-25 14:30:59] request.CRITICAL: Uncaught PHP Exception InvalidArgumentException: "The filename fallback must only contain ASCII characters." at xxx\ezpublish\vendor\symfony\symfony\src\Symfony\Component\HttpFoundation\ResponseHeaderBag.php line 251 {"exception":"[object] (InvalidArgumentException(code: 0): The filename fallback must only contain ASCII characters. at xxx\\ezpublish\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpFoundation\\ResponseHeaderBag.php:251)"} []
This issue was already solved for version 1.6.0 and later (see EZP-26554), but it should be backported to 5.4 since it can also be reproduced there.
Steps to reproduce
- Create new eZ Publish 5.4 installation.
- Create and register a custom bundle (AppBundle).
- In the AppBundle, create a new Controller file named DownloadController.php with the following contents:
<?php namespace AppBundle\Controller; use eZ\Bundle\EzPublishCoreBundle\Controller; use eZ\Bundle\EzPublishIOBundle\BinaryStreamResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\Routing\Annotation\Route; class DownloadController extends Controller { /** * @Route("/content/download/{contentId}/{attributeId}/{fieldIdentifier}/{filename}", name = "custom_content_download") */ public function downloadBinaryFileAction($contentId, $attributeId, $fieldIdentifier, $filename, Request $request) { $contentService = $this->getRepository()->getContentService(); $translationHelper = $this->get('ezpublish.translation_helper'); $ioService = $this->get('ezpublish.fieldType.ezbinaryfile.io_service'); $content = $contentService->loadContent($contentId); $field = $translationHelper->getTranslatedField( $content, $fieldIdentifier, $request->query->has('language') ? $request->query->get('language') : null ); $response = new BinaryStreamResponse($ioService->loadBinaryFile($field->value->id), $ioService); $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename); return $response; } }
- Add the following to the ezpublish/config/routing.yml file:
custom_download: resource: "@AppBundle/Controller/DownloadController.php" type: annotation
- Choose any file and rename it to wontÆØÅwork.ext.
- Open the admin interface, create a new file and upload wontÆØÅwork.ext.
- Embed this file inside a Folder Content Object.
- Open that Content Object with the wontÆØÅwork.ext in the frontend, and try to download the file.
Attachments
Issue Links
- relates to
-
EZP-26554 Fatal error if you try to download files named with non ASCII characters
- Closed