1

I'm working on a Symfony2.8 project, and using Gaufrette to manage files I have stored in an AWS S3 bucket. My files need to be private, so instead of using S3 public URLs, I am trying to stream the files from S3 to my end user. I have it working with StreamWrapper and BinaryFileResponse, but it is incredibly slow -- a 2.5 MB file takes over 20 seconds, and any larger than that fails due to my web server's 30 second time limit. What am I doing wrong?

Here is the code for the relevant action in my controller class:

/**
 * @Route("/docs/get/{file}", name="document_read")
 */
public function documentReadAction(Request $request, $file)
{
    $filesystem = $this->container->get('knp_gaufrette.filesystem_map')->get('docs');
    $map = StreamWrapper::getFilesystemMap();
    $map->set('docs', $filesystem);
    $filepath = 'gaufrette://docs/'.$file;

    return new BinaryFileResponse($filepath);
}
Hayden Schiff
  • 3,280
  • 19
  • 41
  • footnote: I realize that blindly passing `$file` from the request to my file path is a potential security vulnerability -- I'll deal with that later. – Hayden Schiff Oct 20 '16 at 16:06
  • Did you find any answer for this performance issue ? – Félix Veysseyre Jun 20 '17 at 15:10
  • 2
    @FélixVeysseyre Unfortunately, I didn't -- I ultimately gave up on having the files served from my web server, and changed the route to redirect to an S3 pre-signed URL with a 1-hour access token. If you'd like, the code I used to do that is here: https://github.com/oxguy3/jimbox/blob/208103d5eff6b9bd7f5484fa84c0f7b3b4987879/src/AppBundle/Controller/DefaultController.php#L75 – Hayden Schiff Jun 20 '17 at 18:29

0 Answers0