當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。