Hi I'm developing a Laravel project. I need to download an Excel file from Node JS service and pass it to clients. The NodeJS service can work normally by call it directly. But When I call it from Laravel and return to clients it will display the content like a picture below,
Here is my Laravel Controller code,
public function getPassengerInfoExcel($program_id) {
$url = 'http://localhost:3000/excels/paxlist/' . $program_id;
$userName = env('FILE_SERVICE_USERNAME');
$password = env('FILE_SERVICE_PASSWORD');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $userName.':'.$password);
$result = curl_exec($ch);
curl_close($ch);
$response = Response::make($result, 200);
$response->header('Content-Type', 'text/xlsx');
return $response;
}
Please help. Thanks a lot.
CodePudding user response: