【发布时间】:2017-03-24 17:20:37
【问题描述】:
我的 Laravel 5.3 应用程序中有一个方法可以返回如下文件:
public function show(File $file)
{
$path = storage_path('app/' . $file->getPath());
return response()->download($path, $file->name);
}
我正在像这样在 vue.js 中发出 get 请求:
show (file) {
Vue.http.get('/api/file/' + file);
}
结果是这样的:
这里可能有什么问题?我期待我的浏览器下载图像。
--编辑--
当我dd($path); 这是结果:/home/vagrant/Code/forum/storage/app/users/3/messages/xReamZk7vheAyNGkJ8qKgVVsrUbagCdeze.png
路线在我的api.php:
Route::get('/file/{file}', 'File\FileController@show');
当我将它添加到我的 web.php 时,它正在工作。但我需要通过我的 api 访问它!
【问题讨论】:
-
在
download()方法中添加标题作为第三个参数 -
什么样的标题?我以为他们已经包括在内了。
-
你能在你的问题中显示
dd($path)吗? -
@Amit 确定:
"/home/vagrant/Code/forum/storage/app/users/3/messages/xReamZk7vheAyNGkJ8qKgVVsrUbagCdeze.png" -
我怀疑你为什么在
public function show(File $file)中输入 -hintingFile。我认为通过查看您的route文件,它应该是一个字符串,如public function show($file)。