你好,我在下载武力时有一些问题。这是我的代码:
public function download(Request $request, $id) {
$document = Document::find($id);
$s3 = Storage::disk('s3');
$name = substr($document->link, strrpos($document->link, '/') + 1);
$file = $s3->get($name);
$headers = [
'Content-Type' => 'application/pdf',
'Content-Description' => 'File Transfer',
'Content-Disposition' => "attachment; filename={$name}",
'filename'=> $name
];
return response()->download($file);
}
我不明白如何访问好文件
响应:
is_file()期望参数1是有效的路径,字符串给定
有什么想法?
您的标头实际上并未附加到响应上。如果您参考:https://laravel.com/docs/5.5/responses#attaching-headers-to-respons,您会看到在Laravel发送标头的正确方法是:
return response($file)
->header('Content-Type', 'application/pdf')
->header('Content-Description', 'File Transfer')
->header('Content-Disposition', "attachment; filename={$name}")
->header('Filename', $name)
$ file是在reponse()中作为牧师发送的,而不是下载()。