Laravel 5.1 - 如何从S3存储桶下载pdf文件

Joe*_*nks 2 php pdf amazon-s3 laravel

我正在使用Laravel的存储外观,我可以将pdf上传到S3,我也可以获取()其内容,但我无法将其显示或下载到最终用户作为实际的pdf文件.它看起来像原始数据.这是代码:

$file = Storage::disk($storageLocation)->get($urlToPDF);
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename='file.pdf'");
echo $file;
Run Code Online (Sandbox Code Playgroud)

如何才能做到这一点?我检查了几篇文章(和SO),但没有一篇文章适合我.

sta*_*bit 6

我认为这样的事情将在L5.2中完成:

public function download($path)
{
    $fs = Storage::getDriver();
    $stream = $fs->readStream($path);
    return \Response::stream(function() use($stream) {
        fpassthru($stream);
    }, 200, [
        "Content-Type" => $fs->getMimetype($path),
        "Content-Length" => $fs->getSize($path),
        "Content-disposition" => "attachment; filename=\"" .basename($path) . "\"",
        ]);
}
Run Code Online (Sandbox Code Playgroud)