Reputation: 301
I need you help to find a way to be a 'proxy' between the frontend and a third-party software component using Laravel.
The third-party software it is in my company's network and it generate the files on-demand. For sample, If i hit against http://mycompany-third-party.com/12/csv, It will read the data from their database and delivery it to download as response (in this case a csv file).
But I can't allow the users reach out the third-party endpoint directly, so I want to use laravel(guzzle) to ask the file to the third-party and then redirectly to the specific client without store it in my local disk.
How can i do something like this using laravel/guzzle or other library?
Here is my best guess:
$response = Http::withOptions(['stream' => true])->withHeaders([
'X-Metabase-Session' => $this->token,
])->post('http://mycompany-third-party.com/12/csv');
$headers = $response->headers();
return response($response->getBody())->withHeaders($headers);
Upvotes: 2
Views: 1532
Reputation: 301
Hey Guys I study more and I have found a solution. To to this we need to use the Streamed Downloads.
Here is my answer:
$response = Http::withOptions(['stream' => true])->withHeaders([
'X-Metabase-Session' => $this->token,
])->post(your-3th-url);
return response()->streamDownload(function () use ($response) {
echo $response->getBody()->getContents();
}, 'fileName.extType');
see you.
Upvotes: 1