本文整理汇总了PHP中Aws\S3\S3Client::createPresignedRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP S3Client::createPresignedRequest方法的具体用法?PHP S3Client::createPresignedRequest怎么用?PHP S3Client::createPresignedRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aws\S3\S3Client
的用法示例。
在下文中一共展示了S3Client::createPresignedRequest方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* Create a link to a S3 object from a bucket. If expiration is not empty, then it is used to create
* a signed URL
*
* @param string $object The object name (full path)
* @param string $bucket The bucket name
* @param string|int $expiration The Unix timestamp to expire at or a string that can be evaluated by strtotime
* @throws InvalidDomainNameException
* @return string
*/
public function __invoke($object, $bucket = '', $expiration = '')
{
$bucket = trim($bucket ?: $this->getDefaultBucket(), '/');
if (empty($bucket)) {
throw new InvalidDomainNameException('An empty bucket name was given');
}
if ($expiration) {
$command = $this->client->getCommand('GetObject', ['Bucket' => $bucket, 'Key' => $object]);
return $this->client->createPresignedRequest($command, $expiration)->getUri()->__toString();
} else {
return $this->client->getObjectUrl($bucket, $object);
}
}
示例2: getUrlForTransformation
/**
* Get a URL to the resource.
*
* @param \CipeMotion\Medialibrary\Entities\File $file
* @param \CipeMotion\Medialibrary\Entities\Transformation|null $tranformation
* @param bool $fullPreview
* @param bool $download
*
* @return string
*/
public function getUrlForTransformation(File $file, Transformation $tranformation = null, $fullPreview = false, $download = false)
{
if (empty($tranformation)) {
$tranformationName = 'upload';
$extension = $file->extension;
if ($fullPreview && $file->type !== FileTypes::TYPE_IMAGE) {
$tranformationName = 'preview';
$extension = 'jpg';
}
} else {
$tranformationName = $tranformation->name;
$extension = $tranformation->extension;
}
$commandParams = ['ResponseCacheControl' => 'private, max-age=1200', 'ResponseContentType' => $file->mime_type, 'Bucket' => array_get($this->config, 'bucket'), 'Key' => "{$file->id}/{$tranformationName}.{$extension}"];
if ($download) {
$commandParams['ResponseContentDisposition'] = "attachment; filename={$file->filename}";
}
$expires = array_get($this->config, 'presigned.expires', '+20 minutes');
$command = $this->client->getCommand('GetObject', $commandParams);
return (string) $this->client->createPresignedRequest($command, $expires)->getUri();
}
示例3: getPreSignedUrl
public function getPreSignedUrl($bucket, $key, $expiryInMinutes = 10)
{
$this->bucket = $bucket;
$this->key = $key;
$this->scenario = 'delete';
if ($this->validate()) {
try {
$s3Client = new S3Client(['version' => 'latest', 'region' => Yii::$app->params['amazon']['region'], 'credentials' => Yii::$app->params['amazon']['credentials']]);
$cmd = $s3Client->getCommand('GetObject', ['Bucket' => $this->bucket, 'Key' => $this->key]);
$request = $s3Client->createPresignedRequest($cmd, '+' . $expiryInMinutes . ' minutes');
return (string) $request->getUri();
} catch (\Exception $e) {
Yii::error('Error getting pre-signed url from S3. Bucket - ' . $this->bucket . ' Key - ' . $this->key . ' Extra - ' . $e->getMessage());
return false;
}
}
return false;
}
示例4: array
$o_iter = $s3client->getIterator('ListObjects', array('Bucket' => $s3Bucket));
foreach ($o_iter as $o) {
if ($o['Size'] != '0') {
// Because we don't want to list folders
echo "<form enctype='multipart/form-data' name='fileDELForm' method='post' action='index.php' style='border:1px;' >";
$prefixKey = explode("/", $o['Key']);
if ($prefixKey[0] == 'public') {
echo "<a href='http://" . $s3Bucket . "/" . $o['Key'] . "'>";
echo "<img src='http://{$s3Bucket}/" . $o['Key'] . "' style='width:100px;height:100px;'/></a>";
echo "<input type='hidden' name='fileKey' id='fileKey' value='" . $o['Key'] . "' />";
echo "{$o['Key']}";
echo "<input type='submit' name='submit' id='submit' value='Delete' />";
}
if ($prefixKey[0] == 'QSA') {
$objectPre = $s3client->getCommand('GetObject', ['Bucket' => $s3Bucket, 'Key' => $o['Key']]);
$presignedRequest = $s3client->createPresignedRequest($objectPre, '+30 minutes');
$objectURL = (string) $presignedRequest->getUri();
echo "<a href='{$objectURL}' >";
echo "<img src='{$objectURL}' style='width:100px;height:100px;' /></a>";
echo "<input type='hidden' name='fileKey' id='fileKey' value='" . $o['Key'] . "' />";
echo "{$o['Key']}";
echo "<input type='submit' name='submit' id='submit' value='Delete' />";
}
echo "</form>";
}
}
// Check if the UL form has been posted
if ($submit == 'Upload') {
if (isset($s3Bucket) && is_uploaded_file($_FILES['fileUL']['tmp_name'])) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$fileType = finfo_file($finfo, $_FILES['fileUL']['tmp_name']);