Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony Audio Stream with Gaufrette

I am using KnpGaufretteBundle to store audio files. I am able to download a given file to the client like this:

    $filename = "Somefilename.mp3";

    $fs = $this->filesystemMap->get('media_fs');
    $file = $fs->read($filename);

    if($file){
        //Create And Return Response
        $response = new Response();

        $disp = $response->headers->makeDisposition(
            ResponseHeaderBag::DISPOSITION_ATTACHMENT, 
            $variant->getFileName()
        );

        $response->headers->set('Content-Length', $fs->size($filename));
        $response->headers->set('Accept-Ranges', 'bytes');
        $response->headers->set('Content-Transfer-Encoding', 'binary');
        $response->headers->set('Content-Type', 'application/octet-stream');
        $response->headers->set('Content-Disposition', $disp);
        $response->setContent($file);

        return $response;
    }

But now I also want to stream the file to the client, instead of using the attachment content disposition. Basically I want to access it clientside as if I was pointing at an actual mp3 sitting on my server. Does anyone know how this can be done?

like image 805
jspizziri Avatar asked Apr 23 '14 15:04

jspizziri


Video Answer


1 Answers

I solved this by using the streamwrapper... it was this easy.

$filepath = 'gaufrette://myFileSystemName/'.$filename;

$response = new \Symfony\Component\HttpFoundation\BinaryFileResponse($filepath);
like image 86
jspizziri Avatar answered Oct 17 '22 06:10

jspizziri