I have this method in my controller where I'm calling an external URL that returns a PDF file:
public function get()
{
$response = Http::withHeaders(['Content-Type' => 'application/pdf'])
->get('https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf')
->body();
return $response;
}
routes/api.php:
Route::get('/file', [FileController::class, 'get']);
Calling that route in the browser displays this gibberish output instead of the actual file:
If I do return response()->file($file)
, it's throwing an error:
Symfony \ Component\ HttpFoundation\ File \ Exception\ FileNotFoundException
Is there any way to achieve it without having to store the file first?