本文整理汇总了PHP中Aws\S3\S3Client类的典型用法代码示例。如果您正苦于以下问题:PHP S3Client类的具体用法?PHP S3Client怎么用?PHP S3Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了S3Client类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: registerS3Storage
/**
* Criar storage do aws S3
*
* @param array $config
*
* @return StorageInterface
*/
protected function registerS3Storage(array $config)
{
$this->app['nwlaravel.filestorage.storage'] = $this->app->share(function ($app) use($config) {
$s3 = S3Client::factory(array('key' => $config['access'], 'secret' => $config['secret']));
return new S3Storage($config['root'], $s3);
});
}
开发者ID:naturalweb,项目名称:nwlaravel-filestorage,代码行数:14,代码来源:ServiceProvider.php
示例10: getMockS3Client
/**
* @return S3Client
*/
private function getMockS3Client()
{
$mock = new MockPlugin(array(new Response(200, null, '{"Records":[{"r1":"r1"},{"r2":"r2"},{"r3":"r3"}]}'), new Response(200, null, '{}'), new Response(200, null, '{"Records":[{"r4":"r4"},{"r5":"r5"}]}')));
$client = S3Client::factory(array('key' => 'foo', 'secret' => 'bar'));
$client->addSubscriber($mock);
return $client;
}
开发者ID:njbhatt18,项目名称:Amazon_API,代码行数:10,代码来源:LogRecordIteratorTest.php
示例11: __construct
/**
* @inheritdoc
* @param array $values
*/
public function __construct(array $values = [])
{
$values['amazon_s3_client'] = $this->share(function (Application $app) {
return S3Client::factory(array_merge($this->getCredentials(), ['version' => '2006-03-01', 'ssl.certificate_authority' => false]));
});
$values['amazon_s3_credentials_cookie_name'] = 'credentials';
$values['controller.amazon_s3_client'] = $this->share(function (Application $app) {
return new AmazonS3Controller($app['twig'], $app['amazon_s3_client']);
});
$values['controller.authentication'] = $this->share(function (Application $app) {
return new AuthenticationController($app['twig'], $app['amazon_s3_credentials_cookie_name']);
});
parent::__construct($values);
$this->register(new TwigServiceProvider(), ['twig.path' => __DIR__ . '/../views', 'twig.options' => ['cache' => is_writable(__DIR__ . '/..') ? __DIR__ . '/../cache/twig' : false]]);
$this->register(new UrlGeneratorServiceProvider());
$this->register(new ServiceControllerServiceProvider());
$this->get('/login', 'controller.authentication:loginAction')->bind('login')->before(function (Request $request, Application $app) {
$credentials = $this->getCredentials();
if (!empty($credentials)) {
return new RedirectResponse($app['url_generator']->generate('list'));
}
});
$this->post('/login', 'controller.authentication:authenticateAction');
$this->post('/logout', 'controller.authentication:logoutAction')->bind('logout');
$this->get('/{bucket}', 'controller.amazon_s3_client:listAction')->value('bucket', null)->bind('list')->before(function (Request $request, Application $app) {
$credentials = $this->getCredentials();
if (empty($credentials)) {
return $app->handle(Request::create($app['url_generator']->generate('login')), HttpKernelInterface::SUB_REQUEST, false);
}
});
}
开发者ID:ossinkine,项目名称:amazon-s3-client,代码行数:35,代码来源:Application.php
示例12: registerServices
/**
* Register specific services for the module
*/
public function registerServices(DiInterface $di)
{
$config = $di->get('config');
//Registering a dispatcher
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("Promoziti\\Modules\\Business\\Controllers");
return $dispatcher;
});
$di->set('view', function () {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
$view->registerEngines(array('.volt' => function ($view, $di) {
$volt = new VoltEngine($view, $di);
$config = $di->get('config');
$volt->setOptions(array('compileAlways' => true, 'compiledPath' => $config->application->cache_dir . "volt/", 'compiledSeparator' => '_'));
return $volt;
}));
return $view;
});
$di->set('aws_s3', function () use($config) {
//version 2.7 style
$s3 = \Aws\S3\S3Client::factory(array('key' => $config->application->security->aws->key, 'secret' => $config->application->security->aws->secret, 'region' => 'us-west-2', 'version' => '2006-03-01'));
return $s3;
});
}
开发者ID:corzoit,项目名称:phalcon-boilerplate,代码行数:29,代码来源:Module.php
示例13: createS3Adapter
/**
* Creates adapter instance
*
* @param Enlight_Event_EventArgs $args
* @return AdapterInterface
*/
public function createS3Adapter(Enlight_Event_EventArgs $args)
{
$defaultConfig = ['key' => '', 'secret' => '', 'region' => '', 'version' => 'latest', 'bucket' => '', 'prefix' => ''];
$config = array_merge($defaultConfig, $args->get('config'));
$client = S3Client::factory(['credentials' => ['key' => $config['key'], 'secret' => $config['secret']], 'region' => $config['region'], 'version' => $config['version']]);
return new AwsS3Adapter($client, $config['bucket'], $config['prefix']);
}
开发者ID:GerDner,项目名称:luck-docker,代码行数:13,代码来源:Bootstrap.php
示例14: __construct
public function __construct($key, $secret)
{
$this->key = $key;
$this->secret = $secret;
$arr = array('key' => $key, 'secret' => $secret, 'region' => AWS_REGION);
$this->s3 = S3Client::factory($arr);
}
开发者ID:jpbalderas17,项目名称:hris,代码行数:7,代码来源:S3FileSystem.php
示例15: get
public static function get()
{
if (S3ClientBuilder::$client == null) {
S3ClientBuilder::$client = S3Client::factory();
}
return S3ClientBuilder::$client;
}
开发者ID:Cherry-project,项目名称:website,代码行数:7,代码来源:S3ClientBuilder.php
示例16: 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
示例17: 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
示例18: 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
示例19: 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
示例20: 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
注:本文中的Aws\S3\S3Client类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论