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


PHP S3Client::createBucket方法代码示例

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


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

示例1: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     if (!class_exists('\\Aws\\S3\\S3Client')) {
         self::markTestSkipped('Amazon PHP SDK 2 not installed');
     }
     parent::setUpBeforeClass();
     self::$client = \Aws\S3\S3Client::factory(array('key' => self::$s3_key, 'secret' => self::$s3_secret, 'region' => self::$test_region));
     try {
         self::$client->createBucket(array('Bucket' => self::$test_upload_bucket, 'LocationConstraint' => self::$test_region));
         self::$client->waitUntilBucketExists(array('Bucket' => self::$test_upload_bucket));
     } catch (\Aws\S3\Exception\BucketAlreadyOwnedByYouException $exception) {
     }
 }
开发者ID:postelin,项目名称:php-queue,代码行数:13,代码来源:AmazonS3V2Test.php

示例2: no_testBucketAlreadyExists

 /**
  * Create an Amazon S3 bucket
  *
  * @expectedException \Aws\S3\Exception\BucketAlreadyExistsException
  * @example Aws\S3\S3Client::createBucket
  */
 public function no_testBucketAlreadyExists()
 {
     //$client = $this->client;
     //$client->setRegion('us-east-1');
     // @begin
     $this->client->createBucket(array('Bucket' => 'mybucket'));
 }
开发者ID:myrichhub,项目名称:mssapi_php,代码行数:13,代码来源:S3_20060301_Test.php

示例3: __construct

 public function __construct($params)
 {
     if (!isset($params['key']) || !isset($params['secret']) || !isset($params['bucket'])) {
         throw new \Exception("Access Key, Secret and Bucket have to be configured.");
     }
     $this->id = 'amazon::' . $params['key'] . md5($params['secret']);
     $this->bucket = $params['bucket'];
     $scheme = $params['use_ssl'] === 'false' ? 'http' : 'https';
     $this->test = isset($params['test']);
     $this->timeout = !isset($params['timeout']) ? 15 : $params['timeout'];
     $params['region'] = !isset($params['region']) || $params['region'] === '' ? 'eu-west-1' : $params['region'];
     $params['hostname'] = !isset($params['hostname']) || $params['hostname'] === '' ? 's3.amazonaws.com' : $params['hostname'];
     if (!isset($params['port']) || $params['port'] === '') {
         $params['port'] = $params['use_ssl'] === 'false' ? 80 : 443;
     }
     $base_url = $scheme . '://' . $params['hostname'] . ':' . $params['port'] . '/';
     $this->connection = S3Client::factory(array('key' => $params['key'], 'secret' => $params['secret'], 'base_url' => $base_url, 'region' => $params['region']));
     if (!$this->connection->isValidBucketName($this->bucket)) {
         throw new \Exception("The configured bucket name is invalid.");
     }
     if (!$this->connection->doesBucketExist($this->bucket)) {
         try {
             $result = $this->connection->createBucket(array('Bucket' => $this->bucket));
             $this->connection->waitUntilBucketExists(array('Bucket' => $this->bucket, 'waiter.interval' => 1, 'waiter.max_attempts' => 15));
             $this->testTimeout();
         } catch (S3Exception $e) {
             \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
             throw new \Exception("Creation of bucket failed.");
         }
     }
     if (!$this->file_exists('.')) {
         $result = $this->connection->putObject(array('Bucket' => $this->bucket, 'Key' => $this->cleanKey('.'), 'Body' => '', 'ContentType' => 'httpd/unix-directory', 'ContentLength' => 0));
         $this->testTimeout();
     }
 }
开发者ID:Combustible,项目名称:core,代码行数:35,代码来源:amazons3.php

示例4: buildBucket

 /**
  * Attempt to build a bucket (if it doesn't already exist).
  *
  * @param string $bucketName
  */
 protected function buildBucket($bucketName)
 {
     if (!$this->s3Client->doesBucketExist($bucketName, true)) {
         $this->s3Client->createBucket(['ACL' => $this->attachedFile->ACL, 'Bucket' => $bucketName, 'LocationConstraint' => $this->attachedFile->region]);
     }
     $this->bucketExists = true;
 }
开发者ID:a7madev,项目名称:stapler,代码行数:12,代码来源:S3.php

示例5: create

 /**
  * create
  *
  * @param array $params
  *
  * @return boolean
  */
 public function create(array $params = array())
 {
     if ($this->exist()) {
         return true;
     }
     $params['Bucket'] = $this->name;
     return $this->client->createBucket($params);
 }
开发者ID:m6web,项目名称:aws-bundle,代码行数:15,代码来源:Bucket.php

示例6: 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

示例7: setUp

 public function setUp()
 {
     $config = CM_Config::get();
     $className = __CLASS__;
     $key = (string) $config->{$className}->key;
     $secret = (string) $config->{$className}->secret;
     $region = (string) $config->{$className}->region;
     if (empty($key) || empty($secret)) {
         $this->markTestSkipped('Missing `key` or `secret` config.');
     }
     $this->_client = \Aws\S3\S3Client::factory(array('key' => $key, 'secret' => $secret));
     $this->_client->getConfig()->set('curl.options', array('body_as_string' => true));
     // https://github.com/aws/aws-sdk-php/issues/140#issuecomment-25117635
     $this->_bucket = strtolower(str_replace('_', '-', 'test-' . __CLASS__ . uniqid()));
     $this->_filesystem = new CM_File_Filesystem(new CM_File_Filesystem_Adapter_AwsS3($this->_client, $this->_bucket));
     $this->_client->createBucket(array('Bucket' => $this->_bucket, 'LocationConstraint' => $region));
     $this->_client->waitUntilBucketExists(array('Bucket' => $this->_bucket));
     $this->_client->putBucketVersioning(array('Bucket' => $this->_bucket, 'Status' => 'Enabled'));
     $this->_restore = new CMService_AwsS3Versioning_Client($this->_client, $this->_bucket, new CM_OutputStream_Null());
 }
开发者ID:cargomedia,项目名称:cm,代码行数:20,代码来源:ClientTest.php

示例8: testPutBucketLocation

 /**
  * @depends testHeadBucket
  */
 public function testPutBucketLocation()
 {
     $this->log(__METHOD__);
     $bucketName = self::getResourcePrefix() . '-s3eutest';
     try {
         $this->client->headBucket(array('Bucket' => $bucketName));
     } catch (\Exception $e) {
         $this->client->createBucket(array('Bucket' => $bucketName, 'LocationConstraint' => 'EU'));
     }
     $this->client->waitUntil('bucket_exists', array('Bucket' => $bucketName));
     $result = $this->client->getBucketLocation(array('Bucket' => $bucketName));
     $this->assertEquals('EU', $result['Location']);
     $this->client->deleteBucket(array('Bucket' => $bucketName));
 }
开发者ID:myrichhub,项目名称:mssapi_php,代码行数:17,代码来源:IntegrationTest.php

示例9: createContainer

 /**
  * @param array $properties
  * @param array $metadata
  *
  * @throws BadRequestException
  * @throws DfException
  * @internal param array $properties
  * @return array
  */
 public function createContainer($properties, $metadata = [])
 {
     $name = ArrayUtils::get($properties, 'name', ArrayUtils::get($properties, 'path'));
     if (empty($name)) {
         throw new BadRequestException('No name found for container in create request.');
     }
     try {
         $this->checkConnection();
         $this->blobConn->createBucket(['Bucket' => $name]);
         return ['name' => $name, 'path' => $name];
     } catch (\Exception $ex) {
         throw new DfException("Failed to create container '{$name}': " . $ex->getMessage());
     }
 }
开发者ID:pkdevboxy,项目名称:df-aws,代码行数:23,代码来源:S3FileSystem.php

示例10: getConnection

	/**
	 * Returns the connection
	 *
	 * @return S3Client connected client
	 * @throws \Exception if connection could not be made
	 */
	public function getConnection() {
		if (!is_null($this->connection)) {
			return $this->connection;
		}

		$scheme = ($this->params['use_ssl'] === 'false') ? 'http' : 'https';
		$base_url = $scheme . '://' . $this->params['hostname'] . ':' . $this->params['port'] . '/';

		$this->connection = S3Client::factory(array(
			'key' => $this->params['key'],
			'secret' => $this->params['secret'],
			'base_url' => $base_url,
			'region' => $this->params['region']
		));

		if (!$this->connection->isValidBucketName($this->bucket)) {
			throw new \Exception("The configured bucket name is invalid.");
		}

		if (!$this->connection->doesBucketExist($this->bucket)) {
			try {
				$this->connection->createBucket(array(
					'Bucket' => $this->bucket
				));
				$this->connection->waitUntilBucketExists(array(
					'Bucket' => $this->bucket,
					'waiter.interval' => 1,
					'waiter.max_attempts' => 15
				));
				$this->testTimeout();
			} catch (S3Exception $e) {
				\OCP\Util::logException('files_external', $e);
				throw new \Exception('Creation of bucket failed. '.$e->getMessage());
			}
		}

		return $this->connection;
	}
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:44,代码来源:amazons3.php

示例11: createBucket

 /**
  * Creates a new bucket.
  *
  * @param string $bucket
  * @param array  $params
  *
  * @return mixed
  */
 public function createBucket($bucket, array $params = [])
 {
     $params['Bucket'] = $bucket;
     return $this->instance->createBucket($params);
 }
开发者ID:Webiny,项目名称:Framework,代码行数:13,代码来源:S3.php

示例12: Filesystem

<?php

require __DIR__ . '/../vendor/autoload.php';
use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;
use Illuminate\Filesystem\FilesystemAdapter;
//start define settings
$end_point = 'http://webapp.dev:4569';
$bucket_region = 'us-east-1';
$bucket_name = 'default1bucket';
$root_folder_in_bucket = 'news';
$file_path = 'test.jpg';
//end define settings
//start create S3 client
$s3_client = new S3Client(['credentials' => ['key' => 'AKIAIOSFODNN7EXAMPLE', 'secret' => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'], 'region' => $bucket_region, 'version' => 'latest', 'endpoint' => $end_point, 'scheme' => 'http']);
//end create S3 client
//start create bucket
$s3_client->createBucket(['ACL' => 'private', 'Bucket' => $bucket_name, 'CreateBucketConfiguration' => ['LocationConstraint' => $bucket_region]]);
//end create bucket
//start create laravel filesystem adapter
$cloud_adapter = new AwsS3Adapter($s3_client, $bucket_name, $root_folder_in_bucket);
$filesystem = new Filesystem($cloud_adapter);
$disk = new FilesystemAdapter($filesystem);
//end create laravel filesystem adapter
//start put file on disk
if (!$disk->exists($file_path)) {
    $disk->put($file_path, file_get_contents('../resources/assets/img/test.jpg'));
}
//start put file on disk
print "<img src='" . $disk->url($file_path) . "'/>";
开发者ID:rasodu,项目名称:DLEMP,代码行数:31,代码来源:test_server_5_s3.php

示例13: verifyBucketExists

 protected function verifyBucketExists(S3Client $s3Client)
 {
     if (!strlen($this->bucketName)) {
         throw new Exception("[S3Sync::verifyBucketExists] Unable to verify S3 bucket: bucket name not set");
     }
     if (!$s3Client->doesBucketExist($this->bucketName)) {
         $result = $s3Client->createBucket(array('ACL' => 'private', 'Bucket' => $this->bucketName));
         $s3Client->waitUntilBucketExists(array('Bucket' => $this->bucketName));
         if (!$s3Client->doesBucketExist($this->bucketName)) {
             throw new Exception('[S3Sync::verifyBucketExists] Unable to create S3 bucket ' . $this->bucketName);
         }
     }
     return true;
 }
开发者ID:deno085,项目名称:s3-bulk-copy,代码行数:14,代码来源:S3Sync.php

示例14: basename

echo $_POST['phone'];
$uploaddir = '/tmp/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
$s3 = new Aws\S3\S3Client(['version' => 'latest', 'region' => 'us-east-1']);
$bucket = uniqid("php-ars-test-bucket-", false);
# AWS PHP SDK version 3 create bucket
$result = $s3->createBucket(['ACL' => 'public-read', 'Bucket' => $bucket]);
$s3->waitUntil('BucketExists', array('Bucket' => $bucket));
# PHP version 3
$result = $s3->putObject(['ACL' => 'public-read', 'Bucket' => $bucket, 'Key' => "Hello" . $uploadfile, 'ContentType' => $_FILES['userfile']['tmp_name'], 'Body' => fopen($uploadfile, 'r+')]);
$url = $result['ObjectURL'];
echo $url;
$result = $s3->getObject(array('Bucket' => $bucket, 'Key' => "Hello" . $uploadfile, 'ContentType' => $_FILES['userfile']['tmp_name'], 'SaveAs' => '/tmp/originalimage.jpg'));
$image = new Imagick(glob('/tmp/originalimage.jpg'));
$image->oilPaintImage(2);
//Oilpaint image
$image->setImageFormat("jpg");
$image->writeImages('/tmp/modifiedimage.jpg', true);
$modifiedbucket = uniqid("modified-image-", false);
$result = $s3->createBucket(['ACL' => 'public-read', 'Bucket' => $modifiedbucket]);
$resultrendered = $s3->putObject(['ACL' => 'public-read', 'Bucket' => $modifiedbucket, 'Key' => "Hello" . $uploadfile, 'SourceFile' => "/tmp/modifiedimage.jpg", 'ContentType' => $_FILES['userfile']['tmp_name'], 'Body' => fopen("/tmp/modifiedimage.jpg", 'r+')]);
unlink('/tmp/modifiedimage.jpg');
开发者ID:evercoolarshad,项目名称:ITMO544_Application_Setup,代码行数:31,代码来源:result.php

示例15: _createBucket

 /**
  * _createBucket
  * Create the bucket, if not exists, for Amazon S3
  *
  * @param string $bucketName name of the bucket.
  * @return void
  */
 protected function _createBucket($bucketName)
 {
     //TODO: migliorare con un ritorno di qualcosa...
     if (!$this->_s3Client->doesBucketExist($bucketName)) {
         $this->_s3Client->createBucket(array('Bucket' => $bucketName));
     }
     // Poll the bucket until it is accessible
     $this->_s3Client->waitUntil('BucketExists', array('Bucket' => $bucketName));
 }
开发者ID:EnterpriseConsultingDeveloper,项目名称:cakephp-utils,代码行数:16,代码来源:UploadableBehavior.php


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