3

我需要使用BinaryFileResponseLength Headers 和 co 来正确处理视频。我还希望用户允许配置其他存储(S3、Dropbox)。flysystemreadStream方法将返回一个resourceBinaryFileResponse需要一个string路径。处理这个问题的最佳方法是什么?首先将整个文件下载到服务器,直到响应?

4

1 回答 1

8

您可以为此使用 StreamedResponse 类。您必须自己进行一些数据接线,但这很简单。例如,此代码用于启用 PDF 的“强制下载”。

return new StreamedResponse(function () use ($stream) {
    fpassthru($stream);
    exit();
}, 200, [
    'Content-Transfer-Encoding', 'binary',
    'Content-Type' => 'application/pdf',
    'Content-Disposition' => sprintf('attachment; filename="%s.pdf"', $filename),
    'Content-Length' => fstat($stream)['size'],
]);
于 2016-07-17T14:09:17.820 回答