将PDF托管在AWS S3。

huangapple go评论51阅读模式
英文:

host PDF on AWS S3

问题

我想在S3上托管一个PDF文件,并能够与任何人分享链接。我之前见过这样的操作,但是无法弄清楚。

到目前为止,我已将PDF文件上传到一个存储桶中,这部分已经成功。然后,当我点击它,转到“属性”并点击“打开”时,它有效。给我一个类似于 https://my-file.s3.us-east-1.amazonaws.com/my%20file.pdf?lotsofqueries 的URL,我可以从任何地方访问。

问题是,这个链接似乎在大约一小时后会失效。

英文:

I'd like to host a PDF on S3 and be able to share a link to it to anyone. I've seen this done before, but cannot figure it out.

So far I've uploaded the PDF to a bucket which works. Then when I click on it, go to "Properties" and press "Open", it works. Giving me a url such as https://my-file.s3.us-east-1.amazonaws.com/my%20file.pdf?lotsofqueries, which I'm able to access from anywhere.

The issue is, this link seems to expire after an hour or so.

答案1

得分: 1

为了使对象永久公开,您需要执行两个操作:

  1. 禁用 阻止公共访问 到您的存储桶。
  2. 设置 存储桶策略,允许匿名访问该对象,例如:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::<your-bucket>/<name-of-the-file>"
            ]
        }
    ]
}

如果您只想使其在几小时内公开,那么您可以生成一个预签名 URL 用于该文件。

英文:

To make the object permanently public you have to do two things:

  1. Disable Blocking public access to your bucket.
  2. Setup bucket policy allowing for anonymous access to the object, e.g.:
{
    &quot;Version&quot;: &quot;2012-10-17&quot;,
    &quot;Statement&quot;: [
        {
            &quot;Sid&quot;: &quot;PublicReadGetObject&quot;,
            &quot;Effect&quot;: &quot;Allow&quot;,
            &quot;Principal&quot;: &quot;*&quot;,
            &quot;Action&quot;: [
                &quot;s3:GetObject&quot;
            ],
            &quot;Resource&quot;: [
                &quot;arn:aws:s3:::&lt;your-bucket&gt;/&lt;name-of-the-file&gt;&quot;
            ]
        }
    ]
}

If you just want to make it public for few hours only, then you can generated a presigned URL to the file.

huangapple
  • 本文由 发表于 2023年5月18日 10:52:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76277421.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定