I am successfully uploading .pdf files to my AWS S3 bucket using Laravel 5.2. I can go directly to the bucket on AWS S3 and download each .pdf without problem. When I attempt to download certain .pdfs using the code below, the file is unable to be opened by the browser or Acrobat Pro. Here is the code:
$file = Storage::disk('s3')->get($myfile);
// Set headers and force download
Failed to load PDF document
There was an error opening this document. The file is damaged and could not be repaired.
While I am not clear what the issue was with the previous use of
echo $file;, this now works when revised to use the Laravel method
return Response::make($file, 200, $headers);.
// Get the file from s3 $file = Storage::disk('s3')->get($myfile); // Set headers $headers = array( 'Content-type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename=filename=file.pdf" ); // Download return Response::make($file, 200, $headers);