Level 4
You could use Laravel's Streamed Downloads.
return response()->streamDownload(function () use ($response) {
echo $response->getBody();
}, 'example.pdf');
I have an api endpoint that returns a pdf file. How can I use Guzzle to download the file to my user's browser?
public function invoicepdf($invoice_num){
$client = new Client();
$request = new Request('GET', 'http://mysite/getinvoicepdf/'.$invoice_num);
try {
$response = $client->send($request, [
'auth' => ['username', 'password'],
'query' => [
'company_id' => $this->company_id
]
]);
} catch (RequestException $e) {
return false;
}
return true;
}
You could use Laravel's Streamed Downloads.
return response()->streamDownload(function () use ($response) {
echo $response->getBody();
}, 'example.pdf');
Please or to participate in this conversation.