我正在使用Laravel 4& dingo 0.8.3尝试提供动态创建的导出文件作为响应受保护路由的下载并从dingo内部收到错误
我知道L4已经过时了,但这个项目是在一年多前开始的,而且是<距离送货2个月
我可以使用任何解决方法来完成这项工作吗?
该文件包含动态创建的json
(在routes.php中)
Route::group([ 'protected' => true ], function(){
Route::resource('bundle', 'Bundle');
Route::get('bundle/download/{id}', 'Bundle@download');
(在Bundle.php中)
$contents = $this->createBookletExport($id);
$nameForFile = $contents->exportName .'.intbnd';
$pathToFile = "/tmp/".$nameForFile;
File::put( $pathToFile, json_encode($contents) );
return Response::download($pathToFile,$nameForFile);
(在laravel.log中)
[2016-02-21 13:57:24] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined method Symfony\Component\HttpFoundation\BinaryFileResponse::getFormatter()' in [...]/vendor/dingo/api/src/Routing/Router.php:220
(来自dingo / composer.json)
"require-dev": {
"tymon/jwt-auth": "0.4.*",
},
"extra": {
"branch-alias": {
"dev-master": "0.8-dev"
}
}
答案 0 :(得分:0)
我已经解决了这个问题 - 答案是不要使用Response :: download但是要使用Response :: make并添加一些标题(我尝试使用Response :: download的标题无效)
所以这个:
$contents = $this->createBookletExport($id);
$nameForFile = $contents->exportName .'.intbnd';
$pathToFile = "/tmp/".$nameForFile;
File::put( $pathToFile, json_encode($contents) );
return Response::download($pathToFile,$nameForFile);
成为这个:
$contents = $this->createBookletExport($id);
$nameForFile = $contents->exportName .'.intbnd';
$headers = array('Content-Type' => 'application/octet-stream', 'Content-Disposition' => 'attachment; filename='.$nameForFile);
return Response::make(json_encode($contents),200,$headers);
和Dingo!鲍勃是你的叔叔!!
:)