将PDF上传到Amazon S3并在浏览器中显示

时间:2022-11-19 09:27:40

I am uploading PDF's to AmazonS3 manually, using Panic Transmis and via a PHP script/API. For some reason, some display in your browser, and some force download. I have checked permission and can not seem to see any issues, Can anyone help explain how to make PDF's always display in browser ( unless the user specifies otherwise ).

我正在使用Panic Transmis和PHP脚本/ API手动将PDF上传到AmazonS3。出于某种原因,一些显示在您的浏览器中,并有一些强制下载。我已经检查了许可,似乎没有看到任何问题,任何人都可以帮助解释如何使PDF始终显示在浏览器中(除非用户另有说明)。

I don't think it is as browser issue.

我不认为这是浏览器问题。

2 个解决方案

#1


You need to change the Content-Type and Content-Disposition.

您需要更改Content-Type和Content-Disposition。

Content-Type: application/pdf;
Content-Disposition: inline;

Using the AWS S3 console, find the file and using the context menu (right click) select Properties then it's under Metadata.

使用AWS S3控制台,找到该文件并使用上下文菜单(右键单击)选择“属性”,然后选择“元数据”下的“属性”。

Or change this programmatically: http://docs.aws.amazon.com/AWSSDKforPHP/latest/index.html#m=AmazonS3/create_object

或者以编程方式更改:http://docs.aws.amazon.com/AWSSDKforPHP/latest/index.html#m=AmazonS3/create_object

#2


In companion with well's answer, here an example:

与井的答案相吻合,这里有一个例子:

public function save($bucket, $name, $content, $options = [])
{
    $this->s3->putObject([
        'Bucket' => $bucket,
        'Key' => $name,
        'Body' => $content,
    ] + $options);
}

$this->bucket->save('my-bucket', 'SofiaLoren.pdf', $content, [
    'ContentType' => 'application/pdf',
    'ContentDisposition' => 'inline',
]);

#1


You need to change the Content-Type and Content-Disposition.

您需要更改Content-Type和Content-Disposition。

Content-Type: application/pdf;
Content-Disposition: inline;

Using the AWS S3 console, find the file and using the context menu (right click) select Properties then it's under Metadata.

使用AWS S3控制台,找到该文件并使用上下文菜单(右键单击)选择“属性”,然后选择“元数据”下的“属性”。

Or change this programmatically: http://docs.aws.amazon.com/AWSSDKforPHP/latest/index.html#m=AmazonS3/create_object

或者以编程方式更改:http://docs.aws.amazon.com/AWSSDKforPHP/latest/index.html#m=AmazonS3/create_object

#2


In companion with well's answer, here an example:

与井的答案相吻合,这里有一个例子:

public function save($bucket, $name, $content, $options = [])
{
    $this->s3->putObject([
        'Bucket' => $bucket,
        'Key' => $name,
        'Body' => $content,
    ] + $options);
}

$this->bucket->save('my-bucket', 'SofiaLoren.pdf', $content, [
    'ContentType' => 'application/pdf',
    'ContentDisposition' => 'inline',
]);