首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel/Lumen文件响应

Laravel/Lumen文件响应
EN

Stack Overflow用户
提问于 2018-01-23 21:13:48
回答 1查看 6.4K关注 0票数 5

我需要将文件内容(如图像和其他mime类型)从Lumen资源服务器流式传输到Laravel客户端服务器。我知道在Laravel中我可以使用:

代码语言:javascript
复制
$headers = ['Content-Type' => 'image/png']; 
$path = storage_path('/mnt/somestorage/example.png')
return response()->file($path, $headers);

但是,Laravel\Lumen\Http\ResponseFactory中缺少file方法。

任何建议都非常受欢迎。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-24 20:00:18

在Lumen中,您可以使用Symfony的BinaryFileResponse

代码语言:javascript
复制
use Symfony\Component\HttpFoundation\BinaryFileResponse

$type = 'image/png';
$headers = ['Content-Type' => $type];
$path = '/path/to/you/your/file.png';

$response = new BinaryFileResponse($path, 200 , $headers);

return $response;

你可以使用find the documentation here

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48402655

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档