Laravel/Lumen file response

2019-05-25 10:48发布

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条回答
不美不萌又怎样
2楼-- · 2019-05-25 11:30

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.

查看更多
登录 后发表回答