我正在尝试使用laravel下载文件,但是我收到了此错误!
exception: "BadMethodCallException"
file "C:\Users\dev\gaaho\vendor\laravel\framework\src\Illuminate\Support\Traits\Macroable.php"
line 96
message : "Method streamDownload does not exist."
这就是我在控制器中的含义
return response()->streamDownload(function () {
echo GitHub::api('repo')
->contents()
->readme('laravel', 'laravel')['contents'];
}, 'laravel-readme.md');
请帮忙!我正在使用laravel 5.5
答案 0 :(得分:2)
尝试
$name = 'laravel-readme.md';
$headers = [
'Content-Disposition' => 'attachment; filename='. $name,
];
return response()->stream(function() {
echo GitHub::api('repo')
->contents()
->readme('laravel', 'laravel')['contents'];
}, 200, $headers);
看看是否有效。你基本上只是手动设置标题。