1
我成功使用Laravel 5.2將.pdf文件上傳到我的AWS S3存儲桶。我可以直接前往AWS S3上的存儲桶並下載每個.pdf,而不會出現問題。當我嘗試使用下面的代碼下載某些.pdf時,該文件無法被瀏覽器或Acrobat Pro打開。下面是代碼:某些.pdf文件下載在瀏覽器中損壞/ Acrobat Pro - 使用Laravel和AWS S3
$file = Storage::disk('s3')->get($myfile);
// Set headers and force download
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename=file.pdf");
echo $file;
在瀏覽器中,我得到了以下錯誤:Failed to load PDF document
在的Acrobat Pro,我得到以下錯誤:There was an error opening this document. The file is damaged and could not be repaired.
的.PDF是能夠在其他蘋果成功打開程序,例如Preview或Skim。另外,可以成功上傳和下載較舊的.pdf文件。