gliterd/backblaze-b2

用于操作 Backblaze B2 云存储的 PHP SDK。

1.5.4 2022-10-10 02:26 UTC

README

Author Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

backblaze-b2 是操作 Backblaze 的 B2 存储服务的 SDK。

安装

通过 Composer

$ composer require gliterd/backblaze-b2

用法

use BackblazeB2\Client;
use BackblazeB2\Bucket;

$options = ['auth_timeout_seconds' => seconds];

$client = new Client('accountId', 'applicationKey', $options);

$options 是可选的。如果省略,默认超时时间为 12 小时。超时允许长时间运行的客户端对象,以便授权令牌不会过期。

尚未支持 ApplicationKey,请仅使用 MasterKey

返回存储桶详情

$bucket = $client->createBucket([
    'BucketName' => 'my-special-bucket',
    'BucketType' => Bucket::TYPE_PRIVATE // or TYPE_PUBLIC
]);

更改存储桶类型

$updatedBucket = $client->updateBucket([
    'BucketId' => $bucket->getId(),
    'BucketType' => Bucket::TYPE_PUBLIC
]);

列出所有存储桶

$buckets = $client->listBuckets();

删除存储桶

$client->deleteBucket([
    'BucketId' => 'YOUR_BUCKET_ID'
]);

文件上传

$file = $client->upload([
    'BucketName' => 'my-special-bucket',
    'FileName' => 'path/to/upload/to',
    'Body' => 'I am the file content'

    // The file content can also be provided via a resource.
    // 'Body' => fopen('/path/to/input', 'r')
]);

文件下载

$fileContent = $client->download([
    'FileId' => $file->getId()

    // Can also identify the file via bucket and path:
    // 'BucketName' => 'my-special-bucket',
    // 'FileName' => 'path/to/file'

    // Can also save directly to a location on disk. This will cause download() to not return file content.
    // 'SaveAs' => '/path/to/save/location'
]);

文件复制

$copyOfFile = $client->copy([
    'BucketName' => $bucketName,
    'FileName'   => $path,
    'SaveAs'     => $newPath,

    // Can also supply BucketId instead of BucketName
    // Optional are DestinationBucketName or DestinationBucketId
]);

文件删除

$fileDelete = $client->deleteFile([
    'FileId' => $file->getId()

    // Can also identify the file via bucket and path:
    // 'BucketName' => 'my-special-bucket',
    // 'FileName' => 'path/to/file'
]);

列出所有文件

$fileList = $client->listFiles([
    'BucketId' => 'YOUR_BUCKET_ID'
]);

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

测试

$ vendor/bin/phpunit

贡献

请参阅 CONTRIBUTINGCONDUCT 以获取详细信息。

安全性

如果您发现任何与安全性相关的问题,请通过电子邮件 [email protected] 而不是使用问题跟踪器。

鸣谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件