当前位置: 首页>>代码示例>>PHP>>正文


PHP S3Client::headObject方法代码示例

本文整理汇总了PHP中Aws\S3\S3Client::headObject方法的典型用法代码示例。如果您正苦于以下问题:PHP S3Client::headObject方法的具体用法?PHP S3Client::headObject怎么用?PHP S3Client::headObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Aws\S3\S3Client的用法示例。


在下文中一共展示了S3Client::headObject方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: notestPutAndListObjects

 /**
  * @depends testHeadBucket
  */
 public function notestPutAndListObjects()
 {
     $this->client->waitUntil('bucket_exists', array('Bucket' => $this->bucket));
     $command = $this->client->getCommand('PutObject', array('Bucket' => $this->bucket, 'Key' => self::TEST_KEY, 'ContentMD5' => true, 'Body' => 'åbc 123', 'ContentType' => 'application/foo', 'ACP' => $this->acp, 'Metadata' => array('test' => '123', 'abc' => '@pples', 'foo' => '', 'null' => null, 'space' => ' ', 'zero' => '0', 'trim' => ' hi ')));
     self::log("Uploading an object");
     $result = $command->execute();
     // make sure the expect header wasn't sent
     $this->assertNull($command->getRequest()->getHeader('Expect'));
     $this->assertInstanceOf('Guzzle\\Service\\Resource\\Model', $result);
     $this->assertNotEmpty($result['ETag']);
     $this->client->waitUntil('object_exists', array('Bucket' => $this->bucket, 'Key' => self::TEST_KEY));
     self::log("HEAD the object");
     $result = $this->client->headObject(array('Bucket' => $this->bucket, 'Key' => self::TEST_KEY));
     $this->assertEquals('application/foo', $result['ContentType']);
     $this->assertEquals('123', $result['Metadata']['test']);
     $this->assertEquals('@pples', $result['Metadata']['abc']);
     // Ensure the object was created correctly
     self::log("GETting the object");
     $result = $this->client->getObject(array('Bucket' => $this->bucket, 'Key' => self::TEST_KEY));
     $this->assertInstanceOf('Guzzle\\Service\\Resource\\Model', $result);
     $this->assertInstanceOf('Guzzle\\Http\\EntityBody', $result['Body']);
     $this->assertEquals('åbc 123', (string) $result['Body']);
     $this->assertEquals('application/foo', $result['ContentType']);
     $this->assertEquals('123', $result['Metadata']['test']);
     $this->assertEquals('@pples', $result['Metadata']['abc']);
     // Ensure the object was created and we can find it in the iterator
     self::log("Checking if the item is in the ListObjects results");
     $iterator = $this->client->getIterator('ListObjects', array('Bucket' => $this->bucket, 'Prefix' => self::TEST_KEY));
     $objects = $iterator->toArray();
     $this->assertEquals(1, count($objects));
     $this->assertEquals('foo', $objects[0]['Key']);
 }
开发者ID:myrichhub,项目名称:mssapi_php,代码行数:35,代码来源:IntegrationTest.php

示例2: getDfsFileSize

 /**
  * Returns size of a file in the DFS backend, from a relative path.
  *
  * @param string $filePath The relative file path we want to get size of
  *
  * @return int
  */
 public function getDfsFileSize($filePath)
 {
     try {
         $object = $this->s3client->headObject(array('Bucket' => $this->bucket, 'Key' => $filePath));
         return $object['ContentLength'];
     } catch (S3Exception $e) {
         eZDebug::writeError($e->getMessage(), __METHOD__);
         return false;
     }
 }
开发者ID:ezsystems,项目名称:ezdfs-fsbackend-aws-s3,代码行数:17,代码来源:amazon.php

示例3: getMetaData

 protected function getMetaData($path)
 {
     if (!array_key_exists($path, $this->mdCache)) {
         try {
             $this->mdCache[$path] = $this->s3->headObject(['Bucket' => $this->bucket, 'Key' => $path])->toArray();
         } catch (\Exception $e) {
             throw new FileException('Unable to get metadata for file: ' . $path, $e->getCode(), $e);
         }
     }
     return $this->mdCache[$path];
 }
开发者ID:synapsestudios,项目名称:synapse-files,代码行数:11,代码来源:S3FileService.php

示例4: getBlobProperties

 /**
  * List blob
  *
  * @param  string $container Container name
  * @param  string $name      Blob name
  *
  * @return array instance
  * @throws DfException
  */
 public function getBlobProperties($container, $name)
 {
     try {
         $this->checkConnection();
         /** @var \Aws\Result $result */
         $result = $this->blobConn->headObject(['Bucket' => $container, 'Key' => $name]);
         $out = ['name' => $name, 'content_type' => $result->get('ContentType'), 'content_length' => intval($result->get('ContentLength')), 'last_modified' => $result->get('LastModified')];
         return $out;
     } catch (\Exception $ex) {
         throw new DfException('Failed to list blob metadata: ' . $ex->getMessage());
     }
 }
开发者ID:pkdevboxy,项目名称:df-aws,代码行数:21,代码来源:S3FileSystem.php

示例5: _stat

 /**
  * Return stat for given path.
  * Stat contains following fields:
  * - (int)    size    file size in b. required
  * - (int)    ts      file modification time in unix time. required
  * - (string) mime    mimetype. required for folders, others - optionally
  * - (bool)   read    read permissions. required
  * - (bool)   write   write permissions. required
  * - (bool)   locked  is object locked. optionally
  * - (bool)   hidden  is object hidden. optionally
  * - (string) alias   for symlinks - link target path relative to root path. optionally
  * - (string) target  for symlinks - link target path. optionally
  *
  * If file does not exists - returns empty array or false.
  *
  * @param  string  $path    file path
  * @return array|false
  * @author Dmitry (dio) Levashov,
  * @author Alexey Sukhotin
  **/
 protected function _stat($path)
 {
     $stat = array('size' => 0, 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'mime' => 'directory');
     // S3 apparently doesn't understand paths Key with a "/" at the end
     if (substr($path, -1) == "/") {
         $path = substr($path, 0, strlen($path) - 1);
     }
     if ($this->root == $path) {
         return $stat;
     }
     $np = $this->_normpath($path);
     /* @var $obj \Guzzle\Service\Resource\Model */
     try {
         $obj = $this->s3->headObject(['Bucket' => $this->options['bucket'], 'Key' => $np]);
     } catch (NoSuchKeyException $e) {
     }
     if (!isset($obj)) {
         $np .= '/';
         try {
             $obj = $this->s3->headObject(['Bucket' => $this->options['bucket'], 'Key' => $np]);
         } catch (NoSuchKeyException $e) {
         }
     }
     // No obj means it's a folder, or it really doesn't exist
     if (!isset($obj)) {
         if (!$this->_scandir($path)) {
             return false;
         } else {
             return $stat;
         }
     }
     $mime = '';
     if ($obj->hasKey('Last-Modified')) {
         $stat['ts'] = strtotime($obj->get('Last-Modified'));
     }
     try {
         $files = $this->s3->listObjects(['Bucket' => $this->options['bucket'], 'Prefix' => $np, 'Delimiter' => '/'])->get('Contents');
     } catch (Exception $e) {
     }
     $mime = $obj->get('ContentType');
     $stat['mime'] = substr($np, -1) == '/' ? 'directory' : (!$mime ? 'text/plain' : $mime);
     foreach ($files as $file) {
         if ($file['Key'] == $np) {
             $stat['size'] = $file['Size'];
         }
     }
     return $stat;
 }
开发者ID:hen-sen,项目名称:ElFinderPHP,代码行数:68,代码来源:ElFinderVolumeS3.php

示例6: getMimeType

 public function getMimeType($path)
 {
     $path = $this->normalizePath($path);
     if ($this->is_dir($path)) {
         return 'httpd/unix-directory';
     } else {
         if ($this->file_exists($path)) {
             try {
                 $result = $this->connection->headObject(array('Bucket' => $this->bucket, 'Key' => $this->cleanKey($path)));
             } catch (S3Exception $e) {
                 \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
                 return false;
             }
             return $result['ContentType'];
         }
     }
     return false;
 }
开发者ID:Combustible,项目名称:core,代码行数:18,代码来源:amazons3.php

示例7: type

 /**
  * Try to determine and return a files MIME content type.
  *
  * @param  string            $file
  * @return string            The MIME content type
  * @throws \RuntimeException
  */
 public function type($file)
 {
     if (null !== $this->filenameFilter) {
         $file = $this->filenameFilter->filter($file);
     }
     $params = array('Bucket' => $this->getBucket(), 'Key' => $file);
     try {
         $response = $this->s3Client->headObject($params);
     } catch (S3Exception $e) {
         if (!$this->getThrowExceptions()) {
             return null;
         }
         throw new \RuntimeException('Exception thrown by Aws\\S3\\S3Client: ' . $e->getMessage(), null, $e);
     }
     $contentType = (string) $response->get('ContentType');
     if ('' === $contentType) {
         return null;
     }
     return $contentType;
 }
开发者ID:dotsunited,项目名称:cabinet,代码行数:27,代码来源:AmazonS3Adapter.php

示例8: getMetadata

 /**
  * Get metadata for a file
  *
  * @param   string  $path
  * @return  array   file metadata
  */
 public function getMetadata($path)
 {
     $options = $this->getOptions($path);
     $result = $this->client->headObject($options);
     return $this->normalizeObject($result->getAll(), $path);
 }
开发者ID:luoshulin,项目名称:falcon,代码行数:12,代码来源:AwsS3.php

示例9: headObject

 /**
  * headObject
  *
  * @param string $key
  * @param array  $params
  *
  * @return \Guzzle\Service\Resource\Model
  */
 public function headObject($key, array $params = array())
 {
     $params['Key'] = $key;
     $params['Bucket'] = $this->name;
     return $this->client->headObject($params);
 }
开发者ID:m6web,项目名称:aws-bundle,代码行数:14,代码来源:Bucket.php

示例10: getObjectExpirationTime

 /**
  * Get object expiration time.
  * @param string $cacheKey get the cache key.
  * @return integer|boolean the expiration time, false if not found.
  */
 private function getObjectExpirationTime($cacheKey)
 {
     try {
         $result = $this->_client->headObject(['Bucket' => $this->bucket, 'Key' => $cacheKey]);
         return strtotime($result['Expires']);
     } catch (\Aws\S3\Exception\NoSuchKeyException $exc) {
         return false;
     }
 }
开发者ID:urbanindo,项目名称:yii2-s3cache,代码行数:14,代码来源:Cache.php

示例11: fetchObject

 protected function fetchObject(S3Client $client, Bucket $bucket, $key, $store = true, $maxSize = null)
 {
     try {
         // Make sure the file exists.
         $info = $client->headObject(array('Bucket' => $bucket->getName(), 'Key' => $key));
         $contentLength = $info->get('ContentLength');
         if ($contentLength == 0) {
             // This key is likely a directory.
             return false;
         }
         if ($maxSize !== NULL && $maxSize < $contentLength) {
             // The file is too large.
             return false;
         }
     } catch (\Exception $e) {
         return false;
     }
     $result = $client->getObject(array('Bucket' => $bucket->getName(), 'Key' => $key));
     $data = $result->get('Body');
     if ($store) {
         $this->writeToDrive($bucket->getSaveMethod(), $data, $bucket->getDestination(), $key);
         unset($result);
         unset($data);
         return true;
     } else {
         unset($result);
         return $data;
     }
 }
开发者ID:squeegycode,项目名称:s3download,代码行数:29,代码来源:Download.php

示例12: metadata

 /**
  * retrieve a file's metadata
  *
  * @param   string  $filePath
  * @return \Guzzle\Service\Resource\Model
  */
 protected function metadata($filePath)
 {
     return $this->s3->headObject(['Bucket' => $this->bucket, 'Key' => $filePath]);
     //		return $this->s3->get_object_metadata($this->bucket, $filePath);
 }
开发者ID:vovanmix,项目名称:filemanager-laravel4-s3,代码行数:11,代码来源:FilemanagerS3.php


注:本文中的Aws\S3\S3Client::headObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。