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


PHP S3\S3Client类代码示例

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


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

示例1: getLatestFile

 /**
  * Get latest file for a project
  *
  * @param \Aws\S3\S3Client $s3
  * @param Array $config
  * @param InputInterface $input
  *
  * @return mixed
  */
 protected function getLatestFile($s3, $config, $input)
 {
     try {
         // Download latest available backup
         $results = $s3->getIterator('ListObjects', array('Bucket' => $config['bucket'], 'Prefix' => $input->getArgument('name')));
         $newest = null;
         foreach ($results as $item) {
             if (is_null($newest) || $item['LastModified'] > $newest['LastModified']) {
                 $newest = $item;
             }
         }
         if (!$results->count()) {
             // Credentials Exception would have been thrown by now, so now we can safely check for item count.
             throw new \Exception('No backups found for ' . $input->getArgument('name'));
         }
     } catch (InstanceProfileCredentialsException $e) {
         $this->getOutput()->writeln('<error>AWS credentials not found. Please run `configure` command.</error>');
         exit;
     } catch (\Exception $e) {
         $this->getOutput()->writeln('<error>' . $e->getMessage() . '</error>');
         exit;
     }
     $itemKeyChunks = explode('/', $newest['Key']);
     return array_pop($itemKeyChunks);
 }
开发者ID:eniuz,项目名称:magedbm,代码行数:34,代码来源:GetCommand.php

示例2: __construct

 /**
  * When providing the $source argument, you may provide a string referencing
  * the path to a directory on disk to upload, an s3 scheme URI that contains
  * the bucket and key (e.g., "s3://bucket/key"), or an \Iterator object
  * that yields strings containing filenames that are the path to a file on
  * disk or an s3 scheme URI. The "/key" portion of an s3 URI is optional.
  *
  * When providing an iterator for the $source argument, you must also
  * provide a 'base_dir' key value pair in the $options argument.
  *
  * The $dest argument can be the path to a directory on disk or an s3
  * scheme URI (e.g., "s3://bucket/key").
  *
  * The options array can contain the following key value pairs:
  *
  * - base_dir: The directory to remove from the filename when saving.
  * - before: A callable that accepts the following positional arguments:
  *   source, dest, command; where command is an instance of a Command
  *   object. The provided command will be either a GetObject, PutObject,
  *   InitiateMultipartUpload, or UploadPart command.
  * - mup_threshold: Size in bytes in which a multipart upload should be
  *   used instead of PutObject. Defaults to 20971520 (20 MB).
  * - concurrency: Number of files to upload concurrently. Defaults to 5.
  * - debug: Set to true to print out debug information for transfers. Set
  *   to an fopen() resource to write to a specific stream.
  *
  * @param S3Client         $client  Client used for transfers.
  * @param string|\Iterator $source  Where the files are transferred from.
  * @param string           $dest    Where the files are transferred to.
  * @param array            $options Hash of options.
  */
 public function __construct(S3Client $client, $source, $dest, array $options = [])
 {
     $client->registerStreamWrapper();
     if (is_string($source)) {
         $this->base_dir = $source;
         $source = Utils::recursiveDirIterator($source);
     } elseif (!$source instanceof \Iterator) {
         throw new \InvalidArgumentException('source must be the path to a ' . 'directory or an iterator that yields file names.');
     } elseif (!$this->base_dir) {
         throw new \InvalidArgumentException('You must provide the source ' . 'argument as a string or provide the "base_dir" option.');
     }
     $valid = ['mup_threshold', 'base_dir', 'before', 'concurrency', 'debug'];
     foreach ($valid as $opt) {
         if (isset($options[$opt])) {
             $this->{$opt} = $options[$opt];
         }
     }
     if ($this->mup_threshold < 5248000) {
         throw new \InvalidArgumentException('mup_threshold must be >= 5248000');
     }
     // Normalize the destination and source directory.
     $this->dest = rtrim(str_replace('\\', '/', $dest), '/');
     $this->base_dir = rtrim(str_replace('\\', '/', $this->base_dir), '/');
     $this->destScheme = $this->getScheme($this->dest);
     $this->sourceScheme = $this->getScheme($this->base_dir);
     $this->client = $client;
     if ($this->destScheme == 's3') {
         $this->s3Args = $this->getS3Args($this->dest);
     }
     if ($this->debug) {
         $this->wrapDebug();
     }
     $this->source = $this->wrapIterator($source);
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:65,代码来源:Transfer.php

示例3: getObjectUrl

 /**
  * 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);
 }
开发者ID:EnterpriseConsultingDeveloper,项目名称:WhiteRabbitsComponents,代码行数:20,代码来源:WRS3Client.php

示例4: submitForm

 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $category = $form_state->getValue('category');
     $header_bg = $form_state->getValue('header_bg')[0];
     $fid = $form_state->getValue('header_bg')[0];
     $filename = db_select('file_managed', 'f')->condition('f.fid', $fid, '=')->fields('f', array('filename'))->execute()->fetchField();
     $data = db_select('file_managed', 'f')->condition('f.fid', $fid, '=')->fields('f', array('uri'))->execute()->fetchField();
     $config = $this->config('amazons.settings');
     $AccessKeyId = $config->get('AccessKeyId');
     $SecretAccessKey = $config->get('SecretAccessKey');
     $region = $config->get('region');
     $bucket = $config->get('bucketname');
     $s3Client = new \Aws\S3\S3Client(['version' => 'latest', 'region' => $region, 'credentials' => ['key' => $AccessKeyId, 'secret' => $SecretAccessKey]]);
     //Creating bucket dynamically
     // $result1 = $s3Client->createBucket(array('Bucket' => 'mybucket'));
     //
     // echo "<pre>";
     // print_r($result1);
     // exit;
     //$bucket = 'ncdfiles';
     $key = date('ymdhis') . time() . $filename;
     //$data = 'public://ncdfiles/' . $filename;
     $result = $s3Client->putObject(array('Bucket' => $bucket, 'Key' => $key, 'SourceFile' => $data, 'ACL' => 'public-read'));
     db_insert('amazon_s3_data')->fields(array('cat_name' => $category, 'file_path' => $result['ObjectURL'], 'fid' => $fid))->execute();
     drupal_set_message('File uploaded to AWS server');
     return;
 }
开发者ID:National-Control-Devices,项目名称:AmazonS3,代码行数:27,代码来源:MyAwsForm.php

示例5: __construct

 /**
  * @param S3Client $client
  * @param array    $options
  */
 public function __construct(S3Client $client, $options = [])
 {
     parent::__construct($options);
     // We need to register the S3 stream wrapper so that we can take advantage of the base class
     $this->client = $client;
     $this->client->registerStreamWrapper();
 }
开发者ID:GMBN,项目名称:aws-sdk-php-zf2,代码行数:11,代码来源:S3RenameUpload.php

示例6: __construct

 /**
  * Constructor
  *
  * @access public
  * @param  string $key    AWS API Key
  * @param  string $secret AWS API Secret
  * @param  string $region AWS S3 Region
  * @param  string $bucket AWS S3 bucket
  * @param  string $prefix Object prefix
  */
 public function __construct($key, $secret, $region, $bucket, $prefix)
 {
     $this->bucket = $bucket;
     $credentials = new Credentials($key, $secret);
     $this->client = new S3Client(['credentials' => $credentials, 'region' => $region, 'version' => '2006-03-01']);
     $this->client->registerStreamWrapper();
     $this->prefix = $prefix;
 }
开发者ID:kanboard,项目名称:plugin-s3,代码行数:18,代码来源:S3Storage.php

示例7: testCreateBucket

 public function testCreateBucket()
 {
     //start create S3 client
     $client = new S3Client(['credentials' => ['key' => 'AKIAIOSFODNN7EXAMPLE', 'secret' => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'], 'region' => $this->bucket_region, 'version' => 'latest', 'endpoint' => $this->end_point, 'scheme' => 'http']);
     //end create S3 client
     //start create bucket
     $client->createBucket(['ACL' => 'private', 'Bucket' => $this->bucket_name, 'CreateBucketConfiguration' => ['LocationConstraint' => $this->bucket_region]]);
     //end create bucket
     return $client;
 }
开发者ID:rasodu,项目名称:DLEMP,代码行数:10,代码来源:S3Test.php

示例8: __construct

 /**
  * Constructs the PostObject.
  *
  * @param S3Client     $client     Client used with the POST object
  * @param string       $bucket     Bucket to use
  * @param array        $formInputs Associative array of form input fields.
  * @param string|array $jsonPolicy JSON encoded POST policy document. The
  *                                 policy will be base64 encoded and applied
  *                                 to the form on your behalf.
  */
 public function __construct(S3Client $client, $bucket, array $formInputs, $jsonPolicy)
 {
     $this->client = $client;
     $this->bucket = $bucket;
     if (is_array($jsonPolicy)) {
         $jsonPolicy = json_encode($jsonPolicy);
     }
     $this->jsonPolicy = $jsonPolicy;
     $this->formAttributes = ['action' => $this->generateUri(), 'method' => 'POST', 'enctype' => 'multipart/form-data'];
     $this->formInputs = $formInputs + ['key' => '${filename}'];
     $credentials = $client->getCredentials()->wait();
     $this->formInputs += $this->getPolicyAndSignature($credentials);
 }
开发者ID:AWSRandall,项目名称:aws-sdk-php,代码行数:23,代码来源:PostObject.php

示例9: listAction

 /**
  * @param  string $bucket
  * @return string
  */
 public function listAction($bucket)
 {
     $errors = [];
     $buckets = [];
     try {
         $result = $this->s3Client->listBuckets();
         $buckets = $result->get('Buckets');
     } catch (S3Exception $e) {
         $errors[] = sprintf('Cannot retrieve buckets: %s', $e->getMessage());
     }
     $objects = [];
     if (!empty($bucket)) {
         try {
             $maxIteration = 10;
             $iteration = 0;
             $marker = '';
             do {
                 $result = $this->s3Client->listObjects(['Bucket' => $bucket, 'Marker' => $marker]);
                 if ($result->get('Contents')) {
                     $objects = array_merge($objects, $result->get('Contents'));
                 }
                 if (count($objects)) {
                     $marker = $objects[count($objects) - 1]['Key'];
                 }
             } while ($result->get('IsTruncated') && ++$iteration < $maxIteration);
             if ($result->get('IsTruncated')) {
                 $errors[] = sprintf('The number of keys greater than %u, the first part is shown', count($objects));
             }
         } catch (S3Exception $e) {
             $errors[] = sprintf('Cannot retrieve objects: %s', $e->getMessage());
         }
     }
     return $this->twig->render('list.html.twig', ['selected_bucket' => $bucket, 'buckets' => $buckets, 'objects' => $objects, 'errors' => $errors]);
 }
开发者ID:ossinkine,项目名称:amazon-s3-client,代码行数:38,代码来源:AmazonS3Controller.php

示例10: testGetVersioningEnabled

 public function testGetVersioningEnabled()
 {
     $this->_client->putBucketVersioning(array('Bucket' => $this->_bucket, 'Status' => 'Enabled'));
     $this->assertSame(true, $this->_restore->getVersioningEnabled());
     $this->_client->putBucketVersioning(array('Bucket' => $this->_bucket, 'Status' => 'Suspended'));
     $this->assertSame(false, $this->_restore->getVersioningEnabled());
 }
开发者ID:cargomedia,项目名称:cm,代码行数:7,代码来源:ClientTest.php

示例11: uploadString

 /**
  * Uploads string as file to s3
  * @param $name
  * @param $content
  * @param string $contentType
  * @return string
  */
 public function uploadString($name, $content, $contentType = 'text/plain')
 {
     $s3FileName = $this->getFilePathAndUniquePrefix() . $name;
     list($bucket, $prefix) = explode('/', $this->s3path, 2);
     $this->s3client->putObject(['Bucket' => $bucket, 'Key' => (empty($prefix) ? '' : trim($prefix, '/') . '/') . $s3FileName, 'ContentType' => $contentType, 'ACL' => 'private', 'ServerSideEncryption' => 'AES256', 'Body' => $content]);
     return $this->withUrlPrefix($s3FileName);
 }
开发者ID:keboola,项目名称:debug-log-uploader,代码行数:14,代码来源:UploaderS3.php

示例12: writeCsv

 function writeCsv(array $headerRow, array $resultsArray)
 {
     $this->s3Client->registerStreamWrapper();
     $exportBucketPath = $this->getOutputFilePath($this->exportPathWithProtocol);
     $this->writeToDestination($exportBucketPath, $headerRow, $resultsArray);
     return $exportBucketPath;
 }
开发者ID:mixpo,项目名称:form-data-exporter,代码行数:7,代码来源:S3ExporterEngine.php

示例13: delete

 /**
  * {@inheritdoc}
  */
 public function delete($path)
 {
     try {
         $this->s3->deleteObject(['Bucket' => $this->bucket, 'Key' => $path]);
     } catch (AwsExceptionInterface $e) {
         throw Exception\StorageException::deleteError($path, $e);
     }
 }
开发者ID:e-ruiz,项目名称:brick,代码行数:11,代码来源:S3Storage.php

示例14: getUrl

 /**
  * {@inheritdoc}
  */
 public function getUrl($filename)
 {
     $path = $filename;
     if ($this->directory) {
         $path = sprintf('%s/%s', $this->directory, $path);
     }
     return $this->client->getObjectUrl($this->bucket, $path);
 }
开发者ID:harpcio,项目名称:FileUploaderBundle,代码行数:11,代码来源:Aws3Resolver.php

示例15: remove

 /**
  * @param $filename
  * @return \Aws\Result|null
  */
 public function remove($filename)
 {
     $result = null;
     try {
         $result = $this->s3->deleteObject(['Bucket' => $this->bucket, 'Key' => $filename]);
     } catch (\Exception $e) {
     }
     return $result;
 }
开发者ID:Etheriq,项目名称:testSymfoPr,代码行数:13,代码来源:S3.php


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