我的S3桶没有公共访问权限。
当我上传我的文件时,它会出现在我的s3桶中。
例如:
1-URL:
"https://bucketName.s3.eu-central-1.amazonaws.com/pathToFile/filename.pdf"
当我打开这个路径时,我收到这个消息:
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>7G2D8VJSV3M10H92</RequestId>
<HostId>Cc5BwooOhvz6+A9DEByMRFUbBokFqvMWbsBl/QoCiPd/h2xBOr+TPQxigKHIeBpkos7RBGYtUxE=</HostId>
</Error>
这是完美的!
当我在后台…有一个按钮"打开"……当我点击这个按钮时,我将看到我的文件内容:
2-URL:
https://bucketName.s3.eu-central-1.amazonaws.com/pathToFile/filename.pdf?response-content-disposition=inline&X-Amz-Security-Token=TZolawje222luX2VjEJX%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDGV1LWNlbnRyYWwtMSJHMEUCIQCRQdTm3o0LnPzjljwuJceTpdU%2BzpZ1wUwNf1qa6MssJAIgebxp9b7gUWiF8rcyd22eOZ0o7%2Bfj36vKJz3AEbr0K9cq%2FwII3v%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FARACGgw1NzEwMzk5MDgyNzAiDGSpmg0OULYO7wPPlyrTAlQnBekkDsdWKro14yeqCqsCaLejIY1xKljHX96Jv7Ks%2BJ5vQQ2DNg3z7oLrGIKROTln5lms3wo7AKN6pAvt0%2BE6t26dZ2hVqJQxYQJHxniwOSD47cpQZ74chNCH6uC6Q8u0r%2FNlgeOngfH%2BPWyQRCEtFUBFpqH%2BAfKw6KTooRdvJOBa1QLHcNrvqel5NugIYHoFVqiUUbJhcVEzHylIpTwwekySDHFV39nIOCbhu8yvU%2BCopoHLHgdeQD%2FJd50nVHUzsIMFuRMrDAXGuenS5eoUk7Ci%2FTR4%2FjHJ1cMDtY5%2FNf7axxqk7mojvJDavkvMNJdruR5uTLEYtKLo03Kb%2B6xp2EAhh1pzZz8hXtTrhpzzyaG5PInqs%2FH8fMeZcKChdVn8aBxqYQ0A3V9hE0LjlGsSoeHYqCgRqP2QG1GuYyPwXWmgm%2F%2F7mSfLJIESt8CBq1zCkj%2B%2BJBjqzAhLcYlBMrXIpyYBVIa1sP9QMvMtFp2JYjbvRBQV4SchBpS1j5GJQK3%2BpoBX9PeaPL8xvTvRrfoNuB3EZaUI9EgeDYYfHSDYU4F0Mqp%2B6g%2F5KopgrvAHqcx6sF%2F0QyYzkhsp7WpKyTdLzZBma7lydR6svgUBgS6E%2BkA307PzaE6jcuW9lD2Vof5VMy6ciIpBtziXGmSQJ1U6Pukrr%2BojDJ8NgdciL6TEiSRVwrZniIsj6aYPRFzv1Ro%2FCjDZQfDJ%2BhYrEKOcy28KW1ANiCOyloMBmBvMf6D53qTy%2BY7EZIGtIcP8nWl1Am5ESMKQq6QCErO2k731BqmdMdyqFAnNYrieji2JgK8%2B97STgNpYSEselvgpa47qhDvYlrqGBxyjdt0kLq%2FMvfQENd548P8Wf8sp61Ik%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210911T012328Z&X-Amz-SignedHeaders=host&X-Amz-Expires=300&X-Amz-Credential=EUROYJ5FKLWXJKTHAJPT%2F20210910%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Signature=901db2f3543e69f05698ff4c45d188695376ea239cd9a262956bb701f10e06e0
我想知道我如何自己生成这个2-URL ?
在这个url中,我看到了"X-Amz-Security-Token"但我不确定我从哪里得到这个信息?
允许您访问私有Amazon S3对象的神奇URL称为Amazon S3预签名URL,它是一个有时间限制的URL,提供对私有对象的临时访问。
只需几行代码就可以生成预签名的URL。您可以指定URL的有效时间段。在生成预签名URL时,需要使用一组具有访问对象权限的凭据。预签名URL上的"签名"来自这些凭据。
参见:Amazon S3预签名URL
该功能可通过AWS SDK在编程语言中使用。例如,在Python中你可以使用Presigned URLs - Boto3 Docs文档。也可以通过AWS CLI获取:presign - AWS CLI命令参考