[英]Force download from amazon s3 private file in laravel
您好,我在強制下載時遇到了一些問題。 這是我的代碼:
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-responses,您將看到在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()中發送,而不是作為download()發送。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.