Вопрос

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?

Это было полезно?

Решение

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

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

$response = new \Symfony\Component\HttpFoundation\BinaryFileResponse($filepath);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top