简体   繁体   English

Symfony 2.7,使用 StreamedResponse 流式传输文件,请求信息

[英]Symfony 2.7, Stream a file with StreamedResponse, requests for information

I'm working on a symfony app with videos.我正在开发带有视频的 symfony 应用程序。 And i need to stream those videos and then display in an html5 player.我需要流式传输这些视频,然后在 html5 播放器中显示。 I used this blog post : http://ailoo.net/2013/03/stream-a-file-with-streamedresponse-in-symfony/ and i think it's working fine.我使用了这篇博文: http : //ailoo.net/2013/03/stream-a-file-with-streamedresponse-in-symfony/ ,我认为它运行良好。

$response = new StreamedResponse(
        function () use ($file) {
                    readfile($file);
                }, 200, array('Content-Type' => 'video/' . $formatVideo)

            );
return $this->render('SQMovieBundle:Movie:displayMovie.html.twig', array('test' => $response));

But it's the first time i work with things like buffer, i read i have some configuation to do with apache (i'm using mamp on mac os).但这是我第一次使用缓冲区之类的东西,我读到我有一些与 apache 相关的配置(我在 mac os 上使用 mamp)。 And i have no idea for display my video in twig.我不知道在树枝上显示我的视频。

Feel free to give me indications.随意给我指点。

在 Symfony 中有更简洁的文件流传输方式,只需返回BinaryFileResponse类的一个实例:

return new \Symfony\Component\HttpFoundation\BinaryFileResponse($pathToTheFile);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM