https://github.com/quranacademy/b2-php-sdk
An SDK for working with B2 cloud storage
https://github.com/quranacademy/b2-php-sdk
b2 backblaze
Last synced: about 1 year ago
JSON representation
An SDK for working with B2 cloud storage
- Host: GitHub
- URL: https://github.com/quranacademy/b2-php-sdk
- Owner: quranacademy
- License: mit
- Created: 2019-05-19T09:04:18.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-19T12:42:44.000Z (about 7 years ago)
- Last Synced: 2025-01-31T09:18:46.809Z (over 1 year ago)
- Topics: b2, backblaze
- Language: PHP
- Size: 20.5 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
## Backblaze B2 SDK for PHP
[](https://travis-ci.org/quranacademy/b2-php-sdk)
[](https://packagist.org/packages/quranacademy/b2-php-sdk)
[](https://github.com/quranacademy/b2-php-sdk/releases)
[](LICENSE.md)
`b2-php-sdk` is a client library for working with Backblaze B2 storage service. It aims to make using the service as
easy as possible by exposing a clear API and taking influence from other SDKs that you may be familiar with.
**[Backblaze B2 documentation](https://www.backblaze.com/b2/docs/)**
## Installation
To install Backblaze B2 SDK run the command:
```bash
$ composer require quranacademy/b2-php-sdk
```
## Usage
Most methods of the SDK returns the body of the response from B2 API.
Check out [Backblaze B2 documentation](https://www.backblaze.com/b2/docs/) to see what fields will be returned.
```php
use Backblaze\B2Client;
use Backblaze\HttpClient\CurlHttpClient;
$httpClient = new CurlHttpClient();
$client = new B2Client($httpClient);
$client->authorize('accountId', 'applicationKey');
// see "b2_create_bucket" operation in the docs
$bucket = $client->createBucket([
'BucketName' => 'my-bucket',
'BucketType' => B2Client::BUCKET_TYPE_PRIVATE, // or BUCKET_TYPE_PUBLIC
]);
// change the bucket to public
// see "b2_update_bucket"
$updatedBucket = $client->updateBucket([
'BucketId' => $bucket['bucketId'],
'BucketType' => B2Client::BUCKET_TYPE_PUBLIC,
]);
// retrieve a list of buckets on your account
// see "b2_list_buckets"
$buckets = $client->listBuckets();
// delete a bucket
// see "b2_delete_bucket"
$client->deleteBucket([
'BucketId' => $bucket['bucketId'],
]);
// retrieve an array of file objects from a bucket
// see "b2_list_file_names"
$fileList = $client->listFiles([
'BucketId' => '4a48fe8875c6214145260818',
]);
$fileExistence = $client->fileExists([
'BucketId' => '4a48fe8875c6214145260818',
'file' => 'path/to/file',
]);
// upload a file to a bucket
// see "b2_upload_file"
$file = $client->upload([
'BucketId' => '4a48fe8875c6214145260818',
'FileName' => 'path/to/upload/to',
'Body' => 'File content',
// the file content can also be provided via a resource
// 'Body' => fopen('/path/to/source/file', 'r'),
// or as the path to a source file
// 'SourceFile' => '/path/to/source/file',
]);
$fileId = '4_z942111fa0b943d89249a0815_f1001e9fa2c42d9a8_d20170119_m162445_c001_v0001032_t0057';
// download a file from a bucket
$client->download([
'FileId' => $fileId,
'SaveAs' => '/path/to/save/location',
]);
// delete a file from a bucket
// see "b2_delete_file_version"
$fileDelete = $client->deleteFile([
'FileId' => $fileId,
'FileName' => '/path/to/file',
]);
```
## Tests
Tests are run with PHPUnit. After installing PHPUnit via Composer:
```bash
$ vendor/bin/phpunit
```
## Contributors
Feel free to contribute in any way you can whether that be reporting issues, making suggestions or sending PRs.