我的照片存储在 Amazon S3 上。这些图片是私人的,不公开,所以我无法通过直接链接显示它们s3.amazonaws/bucket_name/key_name/image_name.jpg
我知道 Amazon S3 上的图像名称。如何使用 PHP 在我的网站上显示 Amazon S3 图像flower.png 和 house.png 等?
对于那些需要这种行为的人AWS 开发工具包 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();
Ref: https://docs.aws.amazon.com/aws-sdk-php/v3/guide/service/s3-presigned-url.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)