【问题标题】:Certain .pdf File Downloads Damaged In Browser / Acrobat Pro - Using Laravel & AWS S3某些 .pdf 文件下载在浏览器/Acrobat Pro 中损坏 - 使用 Laravel 和 AWS S3
【发布时间】:2016-06-10 01:30:35
【问题描述】:

我正在使用 Laravel 5.2 成功地将 .pdf 文件上传到我的 AWS S3 存储桶。我可以直接进入 AWS S3 上的存储桶并毫无问题地下载每个 .pdf。当我尝试使用以下代码下载某些 .pdf 文件时,浏览器或 Acrobat Pro 无法打开该文件。代码如下:

$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 可以在其他 Apple 程序中成功打开,例如 Preview 或 Skim。此外,可以成功上传和下载较旧的 .pdf 文件。

【问题讨论】:

    标签: php pdf amazon-s3 laravel-5.2


    【解决方案1】:

    虽然我不清楚以前使用 echo $file; 的问题是什么,但现在修改为使用 Laravel 方法 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-22
      • 2021-07-13
      • 1970-01-01
      • 2016-09-22
      • 1970-01-01
      • 2011-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多