Reputation: 651
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.
Upvotes: 5
Views: 8777
Reputation: 96
There is a function in Lumen: https://lumen.laravel.com/docs/8.x/responses#file-downloads
<?php
namespace App\Http\Controllers;
use App\Models\Attachment;
use Illuminate\Http\Request;
class AttachmentController extends AbstractController
{
/**
* Downloads related document by id
*/
public function attachment(Request $request)
{
$path = "path/to/file.pdf";
return response()->download($path);
}
}
Upvotes: 0
Reputation: 651
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.
Upvotes: 8