Files
2025-10-01 17:18:31 -03:00

36 lines
993 B
PHP

<?php
declare(strict_types=1);
namespace App\Actions\Http;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\StreamedResponse;
abstract class ResponseStreamAction extends StreamAction
{
public function stream(string $disposition = 'inline'): StreamedResponse
{
$response = new StreamedResponse();
$disposition = $response->headers->makeDisposition($disposition, $this->streamable->basename());
$response->headers->replace([
'Accept-Ranges' => 'bytes',
'Content-Type' => $this->streamable->mimetype(),
'Content-Length' => $this->streamable->size(),
'Content-Disposition' => $disposition,
]);
$fs = Storage::disk($this->disk());
$response->setCallback(function () use ($fs): void {
$stream = $fs->readStream($this->streamable->path());
fpassthru($stream);
fclose($stream);
});
return $response;
}
}