getObjectUrl() public method

public getObjectUrl ( $bucket, $key )
 /**
  * Returns the URL to an object identified by its bucket and key.
  *
  * The URL returned by this method is not signed nor does it ensure the the
  * bucket and key given to the method exist. If you need a signed URL, then
  * use the {@see \Aws\S3\S3Client::createPresignedRequest} method and get
  * the URI of the signed request.
  *
  * @param string $bucket  The name of the bucket where the object is located
  * @param string $key     The key of the object
  *
  * @return string The URL to the object
  */
 public function getObjectUrl($site, $key)
 {
     $config = $this->_config;
     $bucket = $config['bucket'];
     $builtBucket = strlen($bucket) > 0 ? $site . '.' . $bucket : $site;
     return $this->_s3Client->getObjectUrl($builtBucket, $key);
 }
Example #2
1
 /**
  * @param $path
  * @return string
  */
 public function resolveUrlFor($path)
 {
     $path = trim($this->prefix, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR);
     return $this->client->getObjectUrl($this->bucket, $path);
 }
Example #3
1
 /**
  * getObjectUrl
  *
  * @param string $key
  * @param mixed  $expires
  * @param array  $params
  *
  * @return string
  */
 public function getObjectUrl($key, $expires = null, array $params = array())
 {
     return $this->client->getObjectUrl($this->name, $key, $expires, $params);
 }
 /**
  * {@inheritdoc}
  */
 public function getUrl($filename)
 {
     $path = $filename;
     if ($this->directory) {
         $path = sprintf('%s/%s', $this->directory, $path);
     }
     return $this->client->getObjectUrl($this->bucket, $path);
 }
 /**
  * @param string $html the content to be uploaded.
  * @return string the URL of the uploaded content.
  */
 public function uploadHtml($headers, $html)
 {
     $file = date('YmdHis-') . uniqid("", true);
     $key = (!empty($this->directoryPath) ? $this->directoryPath . '/' : '') . $file . '.html';
     $url = $this->_client->getObjectUrl($this->bucket, $key);
     $result = $this->_client->putObject(array_merge(['ACL' => 'public-read', 'Bucket' => $this->bucket, 'Body' => str_replace($this->archiveUrlTag, $url, $html), 'CacheControl' => 'max-age=31536000, public', 'ContentType' => 'text/html', 'Key' => $key, 'Metadata' => ['X-UID-MailHeader' => \yii\helpers\Json::encode($headers)], 'Expires' => gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime('+5 year'))], $this->uploadOptions));
     if ($result) {
         return $url;
     } else {
         return false;
     }
 }
Example #6
0
 /**
  * {@inheritDoc}
  */
 public function find($path)
 {
     $s3Url = $this->client->getObjectUrl($this->bucket, trim($this->prefix, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR));
     if (false == @getimagesize($s3Url)) {
         return $this->fallbackLoader->find($path);
     }
     $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . basename($s3Url);
     file_put_contents($tmpFilePath, file_get_contents($s3Url));
     $mimeType = $this->mimeTypeGuesser->guess($tmpFilePath);
     unlink($tmpFilePath);
     return new Binary(file_get_contents($s3Url), $mimeType, $this->extensionGuesser->guess($mimeType));
 }
 /**
  * @param $file_contenthash
  * @param $file_statusamazon
  * @return string
  */
 public function getTokenUrl($file_contenthash, $file_statusamazon)
 {
     $fileRelativeLocation = substr($this->path_from_hash($file_contenthash), 1);
     if (!class_exists('S3Util')) {
         require_once __DIR__ . '/S3Util.php';
     }
     $file = S3Util::getPrefix() . $fileRelativeLocation;
     if ($file_statusamazon == 'public') {
         return S3Util::getS3Url() . $fileRelativeLocation;
     }
     return $this->client->getObjectUrl($this->bucket_name, $file, '+5 minutes');
 }
Example #8
0
 /**
  * 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);
     }
 }
Example #9
0
 /**
  * Returns the web accessible URI pointing to the specified persistent resource
  *
  * @param \TYPO3\Flow\Resource\Resource $resource Resource object or the resource hash of the resource
  * @return string The URI
  * @throws Exception
  */
 public function getPublicPersistentResourceUri(Resource $resource)
 {
     if ($this->baseUri != '') {
         return $this->baseUri . $this->getRelativePublicationPathAndFilename($resource, TRUE);
     } else {
         return $this->s3Client->getObjectUrl($this->bucketName, $this->keyPrefix . $this->getRelativePublicationPathAndFilename($resource, TRUE));
     }
 }
Example #10
0
 /**
  * @param $namespace
  * @param $filter
  * @return array
  */
 public function find($namespace, $filter)
 {
     $pattern = self::buildPattern($filter);
     $iterator = $this->s3Client->getIterator('ListObjects', ['Bucket' => $this->basePath, 'Prefix' => Utils::normalizePath($this->relativePath . '/' . $namespace)]);
     $results = [];
     foreach ($iterator as $object) {
         if (!$pattern || preg_match($pattern, '/' . strtr($object['Key'], '\\', '/'))) {
             $url = $this->s3Client->getObjectUrl($this->basePath, $object['Key']);
             $results[$url] = new \SplFileInfo($url);
         }
     }
     return $results;
 }
 /**
  * @inheritdoc
  */
 public function getFileUrl(File $file, array $options)
 {
     return $this->client->getObjectUrl($this->bucket, $this->createFilePath($file));
 }
 /**
  * Returns the URL for an object saved on Amazon S3.
  *
  * @param string $path
  *
  * @return string
  */
 protected function getObjectUrl($path)
 {
     return $this->storage->getObjectUrl($this->bucket, $path, 0, $this->getOptions);
 }
Example #13
0
 /**
  * Return the url for a file upload.
  *
  * @param string $styleName
  *
  * @return string
  */
 public function url($styleName)
 {
     return $this->s3Client->getObjectUrl($this->attachedFile->s3_object_config['Bucket'], $this->path($styleName), null, ['PathStyle' => true]);
 }
Example #14
0
 /**
  * Get remote url, return false in case of error
  *
  * @param string $path Remote Path with folder
  *
  * @return string
  */
 public function getUrl($path)
 {
     return $this->clientS3->getObjectUrl($this->bucket, $path);
 }
Example #15
0
 /**
  * @param $key
  * @return mixed
  */
 public function getUrl($key)
 {
     $this->service->getObjectUrl($this->bucket, $key);
 }
Example #16
0
 /**
  * Returns the public URI for an image by a specific configuration.
  *
  * @param Image $image
  * @param array $filters
  * @return string
  */
 public function getPublicUri(Image $image, array $filters = [])
 {
     // Get a timed url
     return $this->s3->getObjectUrl($this->awsBucket, $this->generateFileName($image, $filters), '+10 minutes');
 }
 /**
  * Returns the URL for an object saved on Amazon S3.
  *
  * @param string $targetPath
  *
  * @return string
  */
 protected function getObjectUrl($targetPath)
 {
     return $this->storage->getObjectUrl($this->bucket, $targetPath, 0, $this->objUrlOptions);
 }
Example #18
0
 /**
  * Returns the URL to an object identified by its bucket and key. If an expiration time is provided, the URL will
  * be signed and set to expire at the provided time.
  *
  * @param string $bucket The name of the bucket where the object is located
  * @param string $key The key of the object
  * @param mixed  $expires The time at which the URL should expire
  * @param array  $args Arguments to the GetObject command. Additionally you can specify a "Scheme" if you would
  *                        like the URL to use a different scheme than what the client is configured to use
  *
  * @return string The URL to the object
  */
 public function getObjectUrl($bucket, $key, $expires = null, array $args = [])
 {
     return $this->instance->getObjectUrl($bucket, $key, $expires, $args);
 }
Example #19
0
 /**
  * Returns the public URI for a file.
  *
  * @param FileModel $fileModel
  * @param array $options
  * @return string
  */
 public function getPublicUri(FileModel $fileModel, array $options = [])
 {
     // Get a timed url
     return $this->s3->getObjectUrl($this->awsBucket, $this->nameGenerator->fileName($fileModel, $options), '+10 minutes');
 }
 /**
  * image
  *
  * Return a file image from Amazon S3.
  *
  * ### Example:
  *
  * `$this->S3File->image($path, $options);`
  *
  * $options are the same as for HTML image, like ['class'=>'img-responsive']
  * if you want to show an HTML piece of code when no image is retrieved pass, for example, in $options ['noimagehtml'=>'<span>no image</span>']
  *
  * $path is the path of the image in the S3 bucket
  *
  * @param string $path
  * @param array $options
  * @return string
  */
 public function image($path, array $options = [])
 {
     $html = '';
     $bucketName = $this->getBucketName($this->request->session()->read('Auth.User.customer_site'));
     if ($path != null && $path != '') {
         try {
             $plainUrl = $this->_s3Client->getObjectUrl($bucketName, $path, '+10 minutes');
             $html .= $this->Html->image($plainUrl, $options);
         } catch (\Exception $e) {
             $html .= $this->getDefaultImage($options);
         }
     } else {
         $html .= $this->getDefaultImage($options);
     }
     return $html;
 }