Laravel/Lumen file response

谁都会走 提交于 2019-12-21 19:49:15

问题


I need to stream file content (such as images and other mime types) from a Lumen resource server to a Laravel client server. I know in Laravel I can use:

$headers = ['Content-Type' => 'image/png']; 
$path = storage_path('/mnt/somestorage/example.png')
return response()->file($path, $headers);

However, the file method is absent in Laravel\Lumen\Http\ResponseFactory.

Any suggestions are very welcome.


回答1:


In Lumen you can use Symfony's BinaryFileResponse.

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;

You can find the documentation here.



来源:https://stackoverflow.com/questions/48402655/laravel-lumen-file-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!