根据此链接http://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-s3.html,我可以轻松创建一个预签名链接,只需将生命周期添加到 getObjectUrl
$signedUrl = $client->getObjectUrl($bucket, 'data.txt', '+10 minutes');
// > https://my-bucket.s3.amazonaws.com/data.txt?AWSAccessKeyId=[...]&Expires=[...]&Signature=[...]
但是我得到一个普通的 url,你知道,没有 awsaccesskeyid 和 expires 参数,
这是我的代码:
$bucket = 'imagenesfc';
$keyname = 'NASimagenes/codigoBarraBoleto/1001000098.png';
$filepath = 'NASimagenes/codigoBarraBoleto';
// Instantiate the client.
$s3 = S3Client::factory(array(
'version' => 'latest',
'region' => 'us-west-1'
));
$signedUrl = $s3->getObjectUrl($bucket, $keyname,'+10 minutes');
// > https://my-bucket.s3.amazonaws.com/data.txt?AWSAccessKeyId=[...]&Expires=[...]&Signature=[...]
echo $signedUrl."<br>";
编辑:我有 AWS_ACCESS_KEY_ID 和 AWS_SECRET_ACCESS_KEY 作为环境变量
我的回声看起来像:
https://s3-us-west-1.amazonaws.com/imagenesfc/NASimagenes/codigoBarraBoleto/1001000098.png
怎么了?