2017-08-03 49 views
1

我想过期设置的URL,但由于某种原因,如预期它不工作和网址保持活着期满过去之后设置过期标识的URL

PHP代码

$object = 'uploads/496c53309bac48e4d65f55d9d66c0ac0.txt'; 
$url = $s3->getObjectUrl($config['s3']['bucket'], $object, '10 seconds'); 

HTML代码

<body> 

<a href="<?php echo $url; ?>">Download Link</a> 

</body> 

我使用AWS SDK 2.7.5

回答

1

“getObjectUr l'只会创建一个常规的S3 url,它只需要两个参数。

要使用presigned网址,需要更多一点的每SDK documentation

// Get a command object from the client and pass in any options 
// available in the GetObject command (e.g. ResponseContentDisposition) 
$command = $client->getCommand('GetObject', array(
    'Bucket' => $bucket, 
    'Key' => 'data.txt', 
    'ResponseContentDisposition' => 'attachment; filename="data.txt"' 
)); 

// Create a signed URL from the command object that will last for 
// 10 minutes from the current time 
$signedUrl = $command->createPresignedUrl('+10 minutes'); 

echo file_get_contents($signedUrl); 
// > Hello!