Using client side I do POST request to Laravel to get back file to browser:
$headers = [
'Content-Type' => 'application/vnd.ms-excel',
'Content-Disposition' => "attachment; filename='Report.xls'"
];
return response()->download(storage_path('app/'.$path.$filename), $filename, $headers);
It returns me binary file in response:
Response headers are:
Try using:
return Storage::download('file.jpg', $name, $headers);
Reference: https://laravel.com/docs/5.8/filesystem#downloading-files
EDIT 1:
Possible solution:
Create a route for getting a xls document (with the GET http method) by his name for example who returns:
return Storage::download('file.jpg', $name, $headers);
Do a POST request, return the 204
http code and with the Location
header.
return response()->header('Location', $url)
When the AJAX success event is called do:
success: function(data, textStatus, request) {
window.open(request.getResponseHeader('Location'), '_blank');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.