Skip to content

Latest commit

 

History

History
80 lines (57 loc) · 1.89 KB

buckets.md

File metadata and controls

80 lines (57 loc) · 1.89 KB

Buckets

Listing Buckets

See b2_list_buckets.

$buckets = $client->listBuckets();

Creating a Bucket

See b2_create_bucket.

$bucketName = '...';

$bucket = $client->createBucket($bucketName);

Warning

By default, createBucket() will create a private bucket, which means authorization will be required to download files. Public buckets can also be created, however the files in these buckets can be downloaded by anyone (without authorization).

Updating a Bucket

See b2_update_bucket.

$bucketId = '..';
$newBucketType = Bucket::TYPE_PUBLIC;

$bucket = $client->updateBucket($bucketId, $newBucketType);

Deleting a Bucket

See b2_delete_bucket.

$bucketId = '..';

$bucket = $client->deleteBucket($bucketId);

CORS Rules and Lifecycle Rules

See CORS rules and lifecycle rules.

$bucketName = '...';
$bucketInfo = [
	'key' => 'value',
];
$corsRules = [
	[
		'corsRuleName'      => 'downloadFromAnyOrigin',
		'allowedOrigins'    => ['https'],
		'allowedHeaders'    => ['range'],
		'allowedOperations' => [
			'b2_download_file_by_id',
			'b2_download_file_by_name',
		],
		'exposeHeaders'     => ['x-bz-content-sha1'],
		'maxAgeSeconds'     => 3600
	]
];
$lifecycleRules = [
	'daysFromHidingToDeleting'  => 1,
	'daysFromUploadingToHiding' => 7,
	'fileNamePrefix'            => 'logs/'
];

$client->createBucket($bucketName, Bucket::TYPE_PRIVATE, $bucketInfo, $corsRules, $lifecycleRules);

// or

$client->updateBucket($bucketid, $bucketType, $bucketInfo, $corsRules, $lifecycleRules, $ifRevisionIs);