2017-09-27 1 views
0

안녕하세요, 강제 다운로드를 할 때 문제가 있습니다. 여기 내 코드입니다 :laravel의 amazon s3 개인 파일에서 다운로드하십시오.

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)가 유효한 경로, 문자열이 될 것으로 예상 주어진

어떤 아이디어?

답변

1

헤더는 실제로 응답에 첨부되지 않습니다. 당신이 참조하는 경우 : 대신 다운로드로()의)

return response($file) 
      ->header('Content-Type', 'application/pdf') 
      ->header('Content-Description', 'File Transfer') 
      ->header('Content-Disposition', "attachment; filename={$name}") 
      ->header('Filename', $name) 

은 $ 파일을합니다 alse (reponse에 paramenter로 전송됩니다 https://laravel.com/docs/5.5/responses#attaching-headers-to-responses 당신은 Laravel에 헤더를 보낼 수있는 적절한 방법이라고 볼 수 있습니다.