[英]How to say browser to start download file?
Using client side I do POST request to Laravel to get back file to browser: 使用客户端,我向Laravel发送POST请求以将文件返回到浏览器:
$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 参考: https : //laravel.com/docs/5.8/filesystem#downloading-files
EDIT 1: 编辑1:
Possible solution: 可能的解决方案:
Create a route for getting a xls document (with the GET http method) by his name for example who returns: 创建一条路线来获取xls文档(使用GET http方法),按他的名字,例如谁返回:
return Storage::download('file.jpg', $name, $headers);
Do a POST request, return the 204
http code and with the Location
header. 进行POST请求,返回
204
http代码并带有Location
标头。
return response()->header('Location', $url)
When the AJAX success event is called do: 调用AJAX成功事件时,请执行以下操作:
success: function(data, textStatus, request) {
window.open(request.getResponseHeader('Location'), '_blank');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.