[英]Force download from amazon s3 private file in laravel
Hello i have some problem with doing a force download. 您好,我在强制下载时遇到了一些问题。 Here is my code :
这是我的代码:
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);
}
i don't get it how to access the good file 我不知道如何访问好的文件
response : 回应:
is_file() expects parameter 1 to be a valid path, string given
is_file()期望参数1为有效路径,给定字符串
Any ideas ? 有任何想法吗 ?
Your headers are not actually attached to the response. 您的标头实际上并未附加到响应中。 If you refer to: https://laravel.com/docs/5.5/responses#attaching-headers-to-responses you will see that the proper way to send headers in Laravel is:
如果您参考: https ://laravel.com/docs/5.5/responses#attaching-headers-to-responses,您将看到在Laravel中发送标头的正确方法是:
return response($file)
->header('Content-Type', 'application/pdf')
->header('Content-Description', 'File Transfer')
->header('Content-Disposition', "attachment; filename={$name}")
->header('Filename', $name)
The $file is alse sent as a paramenter in reponse() instead of as download(). $ file也作为参数在reponse()中发送,而不是作为download()发送。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.