Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\File\File;
public function streamAction()
$file = new File('/path/to/largefile.ext');
// in case you need the container
$container = $this->container;
$response = new StreamedResponse(function() use($container, $file) {
$handle = fopen($file->getRealPath(), 'r');
while (!feof($handle)) {
$buffer = fread($handle, 1024);
echo $buffer;
$response->headers->set('Content-Type', $file->getMimeType());
return $response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.