pkboom/google-storage

dev-master 2020-08-20 16:28 UTC

This package is auto-updated.

Last update: 2024-09-21 01:46:06 UTC


README

Latest Stable Version Total Downloads

此包使与Google Storage协同工作变得轻而易举。一旦设置好,您就可以执行以下操作:

安装

您可以通过composer安装此包

composer require pkboom/google-storage

您必须使用以下命令发布配置

php artisan vendor:publish --provider="Pkboom\GoogleStorage\GoogleStorageServiceProvider"

这将发布一个名为google-storage.php的文件到您的config-directory,内容如下:

return [
    /*
     * Path to the json file containing the credentials.
     */
    'service_account_credentials_json' => storage_path('app/service-account/credentials.json'),
];

如何获取与Google Storage通信的凭证

如何获取与Google日历通信的凭证

云存储身份验证

用法

管理存储桶

use Pkboom\GoogleStorage\Facades\Bucket;

// buckets list
foreach (Bucket::all() as $bucket) {
    $results[] = $bucket->name();
}

// find a bucket
$bucket = Bucket::find($bucketName);

// objects list
foreach ($bucket->objects() as $object) {
    $results[] = $object->name();
}

// objects with a prefix(directory)
foreach ($bucket->prefix($prefix)->objects() as $object) {
    $results[] = $object->name();
}

// create a bucket
try {
    $bucket = Bucket::create($bucketName);
} catch (Exception $e) {
    return response($e->getMessage(), $e->getCode());
}

// delete a bucket
$bucket->delete();

// upload an object
$bucket->upload($filePath);
$bucket->as($newName)->upload($filePath);

// copy an object
$bucket->copy($bucketName);
$bucket->as('backup/'.$newName)->copy($bucketName);

// move an object
$bucket->move($bucketName);
$bucket->as('backup/'.$newName)->move($bucketName);