Problem/Motivation
When using the
S3 File Integration module β
, this module throws a fatal error similar to the following:
The website encountered an unexpected error. Try again later.
Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException: The file "s3://2023-08/Nutritional_Guide_8.23.pdf" does not exist in Symfony\Component\HttpFoundation\File\File->__construct() (line 36 of /Users/ronald.ferguson/Sites/Projects/CLIENT_SITE/vendor/symfony/http-foundation/File/File.php).
Symfony\Component\HttpFoundation\BinaryFileResponse->setFile('s3://2023-08/Nutritional_Guide_8.23.pdf', NULL, , 1) (Line: 52)
Symfony\Component\HttpFoundation\BinaryFileResponse->__construct('s3://2023-08/Nutritional_Guide_8.23.pdf', 200, Array, 1) (Line: 157)
Drupal\media_entity_download\Controller\DownloadController->download(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 270)
Drupal\shield\ShieldMiddleware->bypass(Object, 1, 1) (Line: 137)
Drupal\shield\ShieldMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
To reproduce this issue, install and configure the S3FS module and migrate files to S3 as per the module instructions. For any media item, navigate to http://yoursite.com/media/[media-id]/download. This will generate a 500 error with a message similar to the one above.
The issue at the core of this is in the Symfony\Component\HttpFoundation\BinaryFileResponse
. This response type is expecting all of the files to be on the local file system. I propose that any $scheme that is not public or private be considered a 'remote' stream and use the Symfony\Component\HttpFoundation\StreamedResponse
. I'm currently working up a fix using this method because in theory, it is a suitable replacement.