quranacademy / b2-php-sdk
B2云存储的SDK
dev-master
2019-05-19 11:59 UTC
Requires
- php: >=7.1
- ext-curl: *
- ext-json: *
- ext-mbstring: *
Requires (Dev)
- mockery/mockery: ^1.2
- phpunit/phpunit: ^6.5
This package is auto-updated.
Last update: 2024-09-20 00:43:32 UTC
README
b2-php-sdk
是用于与Backblaze B2存储服务工作的客户端库。它通过提供一个清晰的API并借鉴你可能熟悉的其他SDK的影响,旨在尽可能简化使用此服务。
安装
要安装Backblaze B2 SDK,请运行以下命令
$ composer require quranacademy/b2-php-sdk
使用
SDK的大多数方法都返回来自B2 API的响应正文。查看Backblaze B2文档,了解将返回哪些字段。
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', ]);
测试
测试使用PHPUnit运行。在通过Composer安装PHPUnit后
$ vendor/bin/phpunit
贡献者
请随时以任何方式贡献,无论是报告问题、提出建议还是发送PR。