英文:
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
为了使对象永久公开,您需要执行两个操作:
{
"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:
- Disable Blocking public access to your bucket.
- Setup bucket policy allowing for anonymous access to the object, e.g.:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::<your-bucket>/<name-of-the-file>"
]
}
]
}
If you just want to make it public for few hours only, then you can generated a presigned URL to the file.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论