gpt4 book ai didi

php - 如何在我的网站上显示来 self 的 Amazon S3 的图像?

转载 作者:可可西里 更新时间:2023-11-01 13:13:12 24 4
gpt4 key购买 nike

我在 Amazon S3 上有我的照片。这些图片是私有(private)的而不是公开的,所以我无法通过直接链接显示它们 s3.amazonaws/bucket_name/key_name/image_name.jpg

我知道 Amazon S3 上的图像名称。我如何使用 PHP 在我的网站上显示 Amazon S3 图像 flower.png 和 house.png 等?

最佳答案

对于那些使用 AWS SDK v3 需要此行为的用户,如果您使用“+10 分钟”作为第三个参数直接调用 getObjectUrl,它将始终返回纯 URL。那是因为方法变了。要获取预签名链接,请执行以下操作:

//Get an instance of S3 Client. This is one one to do it:
$s3Client = new S3Client([
'version' => 'latest',
'region' => 'us-west-2', //Region of the bucket
'credentials' => array(
'key' => 'YOUR-ACCOUNT-KEY',
'secret' => 'YOUR-ACCOUNT-SECRET',
)
]);

//Get a command to GetObject
$cmd = $s3Client->getCommand('GetObject', [
'Bucket' => 'YOUR-BUCKET-NAME',
'Key' => 'YOUR-FILE-KEY'
]);

//The period of availability
$request = $s3Client->createPresignedRequest($cmd, '+10 minutes');

//Get the pre-signed URL
$signedUrl = (string) $request->getUri();

引用:https://docs.aws.amazon.com/aws-sdk-php/v3/guide/service/s3-presigned-url.html

关于php - 如何在我的网站上显示来 self 的 Amazon S3 的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27768596/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com