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


PHP S3Client::copyObject方法代码示例

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


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

示例1: testCopiesObjects

 /**
  * @depends testPutObjectsWithUtf8Keys
  */
 public function testCopiesObjects()
 {
     self::log("Copying the object");
     $result = $this->client->copyObject(array('Bucket' => $this->bucket, 'Key' => 'copy-key', 'CopySource' => $this->bucket . '/' . self::TEST_KEY, 'MetadataDirective' => 'COPY', 'ServerSideEncryption' => 'AES256'));
     $this->assertNotEmpty($result['ETag']);
     $this->assertEquals('AES256', $result['ServerSideEncryption']);
     $this->assertNotEmpty($result['LastModified']);
     $this->client->waitUntil('object_exists', array('Bucket' => $this->bucket, 'Key' => 'copy-key'));
 }
开发者ID:myrichhub,项目名称:mssapi_php,代码行数:12,代码来源:IntegrationTest.php

示例2: copyObject

 /**
  * Creates a copy of an object that is already stored in Amazon S3.
  *
  * @param string $sourceBucket
  * @param string $sourceKey
  * @param string $targetBucket
  * @param string $targetKey
  * @param array  $params
  *
  * @return mixed
  */
 public function copyObject($sourceBucket, $sourceKey, $targetBucket, $targetKey, array $params = [])
 {
     $params['Bucket'] = $targetBucket;
     $params['Key'] = $targetKey;
     $params['CopySource'] = urlencode($sourceBucket . '/' . $sourceKey);
     return $this->instance->copyObject($params);
 }
开发者ID:Webiny,项目名称:Framework,代码行数:18,代码来源:S3.php

示例3: rename

 /**
  * rename file/directory
  *
  * @return string
  */
 public function rename()
 {
     $oldPath = $this->sanitizePath($this->get['old']);
     $isDir = $this->isDir($this->metadata("{$oldPath}"));
     $oldPath .= $isDir ? '/' : '';
     $contents = $isDir ? $this->s3->listObjects(['Bucket' => $this->bucket, 'Prefix' => $oldPath])['Contents'] : array();
     // NOTE: we do this instead of isDir as we only care if there are files under this prefix
     if (count($contents) > 1) {
         $this->error('Unfortunately, we are currently unable to rename a non-empty directory.', false);
     }
     $pathInfo = pathinfo($oldPath);
     $dirName = $pathInfo['dirname'];
     $baseName = $pathInfo['basename'];
     $newFile = $this->get['new'];
     $newPath = join('/', array($dirName, $newFile));
     if ($isDir) {
         $response = $this->createDirectory($newPath);
     } else {
         $response = $this->s3->copyObject(['Bucket' => $this->bucket, 'CopySource' => urlencode($this->bucket . '/' . $oldPath), 'Key' => $newPath]);
         //				array('bucket' => $this->bucket, 'filename' => $oldPath),
         //				array('bucket' => $this->bucket, 'filename' => $newPath),
         //				array('acl' => CannedAcl::PUBLIC_READ)
         //			);
     }
     if (!empty($response)) {
         $this->s3->deleteObject(['Bucket' => $this->bucket, 'Key' => $oldPath]);
         //$this->bucket, $oldPath);
     }
     return array('Error' => '', 'Code' => 0, 'Old Path' => $oldPath, 'Old Name' => $baseName, 'New Path' => $newPath, 'New Name' => $newFile);
 }
开发者ID:vovanmix,项目名称:filemanager-laravel4-s3,代码行数:35,代码来源:FilemanagerS3.php

示例4: copy

 /**
  * Copy Object
  *
  * @param string $from Path From
  * @param string $to   Path To
  *
  * @return bool
  */
 public function copy($from, $to)
 {
     $from = ltrim($from, "/");
     $to = ltrim($to, "/");
     if (!$this->exists($from)) {
         $path = $this->bucket . "/" . $from;
         throw new ExceptionStorage("Object {$path} Not found", static::E_NOT_IS_DIR);
     }
     if ($this->exists($to)) {
         $path = $this->bucket . "/" . $to;
         throw new ExceptionStorage("Object {$path} exists");
     }
     // Copia Object
     $this->clientS3->copyObject(array('Bucket' => $this->bucket, 'Key' => $to, 'CopySource' => $this->bucket . '/' . rawurlencode($from), 'ACL' => static::ACL_PUBLIC_READ, 'MetadataDirective' => 'COPY'));
     $pathFrom = trim($from, '/') . '/';
     $iterator = $this->clientS3->getIterator('ListObjects', array('Bucket' => $this->bucket, 'Prefix' => $pathFrom));
     foreach ($iterator as $object) {
         $pattern = preg_quote($pathFrom, "/");
         $Key = preg_replace("/^{$pattern}/", "", $object['Key']);
         if (!empty($Key)) {
             $pattern = preg_quote($pathFrom, "/");
             $Key = preg_replace("/^{$pattern}/", "", $object['Key']);
             $origem = $this->bucket . '/' . $object['Key'];
             $destino = trim($to, "/") . "/" . $Key;
             // Copia Object
             $this->clientS3->copyObject(array('Bucket' => $this->bucket, 'Key' => $destino, 'CopySource' => $origem, 'ACL' => static::ACL_PUBLIC_READ, 'MetadataDirective' => 'COPY'));
         }
     }
     return true;
 }
开发者ID:naturalweb,项目名称:filestorage,代码行数:38,代码来源:S3Storage.php

示例5: rename

 /**
  * Rename a file
  *
  * @param   string  $path
  * @param   string  $newpath
  * @return  array   file metadata
  */
 public function rename($path, $newpath)
 {
     $options = $this->getOptions($newpath, array('Bucket' => $this->bucket, 'CopySource' => $this->bucket . '/' . $this->prefix($path)));
     $result = $this->client->copyObject($options)->getAll();
     $result = $this->normalizeObject($result, $newpath);
     $this->delete($path);
     return $result;
 }
开发者ID:luoshulin,项目名称:falcon,代码行数:15,代码来源:AwsS3.php

示例6: rename

 /**
  *
  * @param string $oldName
  * @param string $newName
  *
  * @return bool - true
  */
 public function rename($oldName, $newName)
 {
     try {
         $this->s3->copyObject(['Bucket' => $this->bucket, 'Key' => $newName, 'CopySource' => sprintf('%s/%s', $this->bucket, $oldName)]);
         $this->delete($oldName);
     } catch (\Exception $e) {
         throw new FileException('File was not renamed', $e->getCode(), $e);
     }
     return true;
 }
开发者ID:synapsestudios,项目名称:synapse-files,代码行数:17,代码来源:S3FileService.php

示例7: copyBlob

 /**
  * @param string $container
  * @param string $name
  * @param string $src_container
  * @param string $src_name
  * @param array  $properties
  *
  * @throws DfException
  *
  * @param array  $properties
  */
 public function copyBlob($container = '', $name = '', $src_container = '', $src_name = '', $properties = [])
 {
     try {
         $this->checkConnection();
         $options = ['Bucket' => $container, 'Key' => $name, 'CopySource' => urlencode($src_container . '/' . $src_name)];
         $result = $this->blobConn->copyObject($options);
     } catch (\Exception $ex) {
         throw new DfException('Failed to copy blob "' . $name . '": ' . $ex->getMessage());
     }
 }
开发者ID:pkdevboxy,项目名称:df-aws,代码行数:21,代码来源:S3FileSystem.php

示例8: renameOnDFS

 /**
  * Renamed DFS file $oldPath to DFS file $newPath
  *
  * @param string $oldPath
  * @param string $newPath
  *
  * @return bool
  */
 public function renameOnDFS($oldPath, $newPath)
 {
     try {
         $this->s3client->copyObject(array('Bucket' => $this->bucket, 'Key' => $newPath, 'CopySource' => $this->bucket . "/" . $oldPath, 'ACL' => 'public-read'));
         $this->delete($oldPath);
         return true;
     } catch (S3Exception $e) {
         eZDebug::writeError($e->getMessage(), __METHOD__);
         return false;
     }
 }
开发者ID:ezsystems,项目名称:ezdfs-fsbackend-aws-s3,代码行数:19,代码来源:amazon.php

示例9: _copy

 /**
  * Copy file into another file
  * S3 does not preserve ACL for a file
  * also can be used only for file smaller than 5GB
  *
  * @param  string  $source     source file path
  * @param  string  $targetDir  target directory path
  * @param  string  $name       new file name
  * @return Guzzle\Service\Resource\Model
  **/
 protected function _copy($source, $targetDir, $name)
 {
     $stat = $this->stat($source);
     if ($stat['mime'] == 'directory') {
         $newDir = $this->_mkdir($targetDir, $name);
         $items = $this->_scandir($source);
         foreach ($items as $item) {
             $this->_copy($item, $newDir, basename($item));
         }
         $this->clearcache();
         return $newDir;
     }
     $this->clearcache();
     return $this->s3->copyObject(array("Bucket" => $this->bucket, "Key" => $this->pathToKey($this->_joinPath($targetDir, $name)), "CopySource" => $this->bucket . "/" . $this->pathToKey($source), "ACL" => $this->options['acl']));
 }
开发者ID:nguyentuansieu,项目名称:BioMedia,代码行数:25,代码来源:elFinderVolumeS3.class.php

示例10: copy

 /**
  * Copy a file internally.
  *
  * @param  string            $src
  * @param  string            $dest
  * @return boolean           Whether the file was copied
  * @throws \RuntimeException
  */
 public function copy($src, $dest)
 {
     if (null !== $this->filenameFilter) {
         $src = $this->filenameFilter->filter($src);
         $dest = $this->filenameFilter->filter($dest);
     }
     $params = array('Bucket' => $this->getBucket(), 'Key' => $dest, 'ACL' => $this->getAcl(), 'StorageClass' => $this->getStorageClass(), 'CopySource' => '/' . $this->getBucket() . '/' . rawurlencode($src));
     try {
         $this->s3Client->copyObject($params);
     } catch (S3Exception $e) {
         if (!$this->getThrowExceptions()) {
             return false;
         }
         throw new \RuntimeException('Exception thrown by Aws\\S3\\S3Client: ' . $e->getMessage(), null, $e);
     }
     return true;
 }
开发者ID:dotsunited,项目名称:cabinet,代码行数:25,代码来源:AmazonS3Adapter.php

示例11: copy

 public function copy($path1, $path2)
 {
     $path1 = $this->normalizePath($path1);
     $path2 = $this->normalizePath($path2);
     if ($this->is_file($path1)) {
         try {
             $result = $this->connection->copyObject(array('Bucket' => $this->bucket, 'Key' => $this->cleanKey($path2), 'CopySource' => S3Client::encodeKey($this->bucket . '/' . $path1)));
             $this->testTimeout();
         } catch (S3Exception $e) {
             \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
             return false;
         }
     } else {
         if ($this->file_exists($path2)) {
             return false;
         }
         try {
             $result = $this->connection->copyObject(array('Bucket' => $this->bucket, 'Key' => $path2 . '/', 'CopySource' => S3Client::encodeKey($this->bucket . '/' . $path1 . '/')));
             $this->testTimeout();
         } catch (S3Exception $e) {
             \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
             return false;
         }
         $dh = $this->opendir($path1);
         if (is_resource($dh)) {
             while (($file = readdir($dh)) !== false) {
                 if ($file === '.' || $file === '..') {
                     continue;
                 }
                 $source = $path1 . '/' . $file;
                 $target = $path2 . '/' . $file;
                 $this->copy($source, $target);
             }
         }
     }
     return true;
 }
开发者ID:Combustible,项目名称:core,代码行数:37,代码来源:amazons3.php

示例12: publishResource

 /**
  * Publishes the given persistent resource from the given storage
  *
  * @param \TYPO3\Flow\Resource\Resource $resource The resource to publish
  * @param CollectionInterface $collection The collection the given resource belongs to
  * @return void
  * @throws Exception
  */
 public function publishResource(Resource $resource, CollectionInterface $collection)
 {
     $storage = $collection->getStorage();
     if ($storage instanceof S3Storage) {
         if ($storage->getBucketName() === $this->bucketName && $storage->getKeyPrefix() === $this->keyPrefix) {
             throw new Exception(sprintf('Could not publish resource with SHA1 hash %s of collection %s because the source and target S3 bucket is the same, with identical key prefixes. Either choose a different bucket or at least key prefix for the target.', $resource->getSha1(), $collection->getName()), 1428929563);
         }
         try {
             $sourceObjectArn = $storage->getBucketName() . '/' . $storage->getKeyPrefix() . $resource->getSha1();
             $objectName = $this->keyPrefix . $this->getRelativePublicationPathAndFilename($resource);
             $options = array('ACL' => 'public-read', 'Bucket' => $this->bucketName, 'CopySource' => urlencode($sourceObjectArn), 'ContentType' => $resource->getMediaType(), 'MetadataDirective' => 'REPLACE', 'Key' => $objectName);
             $this->s3Client->copyObject($options);
             $this->systemLogger->log(sprintf('Successfully published resource as object "%s" (MD5: %s) by copying from bucket "%s" to bucket "%s"', $objectName, $resource->getMd5() ?: 'unknown', $storage->getBucketName(), $this->bucketName), LOG_DEBUG);
         } catch (S3Exception $e) {
             throw new Exception(sprintf('Could not publish resource with SHA1 hash %s of collection %s (source object: %s) through "CopyObject" because the S3 client reported an error: %s', $resource->getSha1(), $collection->getName(), $sourceObjectArn, $e->getMessage()), 1428999574);
         }
     } else {
         $sourceStream = $resource->getStream();
         if ($sourceStream === false) {
             throw new Exception(sprintf('Could not publish resource with SHA1 hash %s of collection %s because there seems to be no corresponding data in the storage.', $resource->getSha1(), $collection->getName()), 1428929649);
         }
         $this->publishFile($sourceStream, $this->getRelativePublicationPathAndFilename($resource), $resource);
     }
 }
开发者ID:sebids,项目名称:flow-aws-s3,代码行数:32,代码来源:S3Target.php

示例13: copyObject

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

示例14: copy

 /**
  * Copy a file
  *
  * @param   string  $path
  * @param   string  $newpath
  * @return  array   file metadata
  */
 public function copy($path, $newpath)
 {
     $options = $this->getOptions($newpath, array('Bucket' => $this->bucket, 'CopySource' => $this->bucket . '/' . $this->applyPathPrefix($path), 'ACL' => $this->getObjectACL($path)));
     $result = $this->client->copyObject($options)->getAll();
     return $this->normalizeObject($result, $newpath);
 }
开发者ID:bogolubov,项目名称:owncollab_talks-1,代码行数:13,代码来源:AwsS3.php


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