giggsey/psr7-stream-response

Build a Symfony Response from a PSR-7 Stream

Maintainers

Package info

github.com/giggsey/psr7-stream-response

pkg:composer/giggsey/psr7-stream-response

Statistics

Installs: 76 680

Dependents: 0

Suggesters: 0

Stars: 5

Open Issues: 0

1.2.0 2026-05-19 18:23 UTC

This package is auto-updated.

Last update: 2026-05-19 18:24:24 UTC


README

Why?

Symfony's BinaryFileResponse allows presenting files to download to HTTP Clients. However, this expects full file paths. Some projects may want to stream a PSR-7 Stream to the client instead.

How to use

Instead of returning a BinaryFileResponse, create a PSR7StreamResponse, and return that.

Before

$response = new BinaryFileResponse($filePath);
$response = $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'my-file.mp3');

return $response;

After

$response = new PSR7StreamResponse($stream, 'audio/mpeg');
$response = $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'my-file.mp3');

return $response;