tes/laravel-google-drive-storage
Composer 安装命令:
composer require tes/laravel-google-drive-storage
包简介
A Laravel package that integrates Google Drive as a storage option, allowing seamless file uploads, folder creation, and file management directly from your Laravel application.
README 文档
README
A Laravel package that integrates Google Drive as a storage option, allowing seamless file uploads, folder creation, and file management directly from your Laravel application.
Installation
To install this package, you need to include it in your composer.json file:
composer require tes/laravel-google-drive-storage
Configuration
Ensure you have the following environment variables set in your .env file:
GOOGLE_DRIVE_CLIENT_ID=your_client_id GOOGLE_DRIVE_CLIENT_SECRET=your_client_secret GOOGLE_DRIVE_REFRESH_TOKEN=your_refresh_token GOOGLE_DRIVE_FOLDER_ID=your_folder_id_optional
Obtaining a Refresh Token To obtain a refresh token, follow the guide provided in this article: How to Generate Refresh Token and Use Them to Access Google API.
Also you need to add in file config/filesystems.php file:
'disks' => [
.........
'google' => [
'driver' => 'google',
'clientId' => env('GOOGLE_DRIVE_CLIENT_ID', ''),
'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET', ''),
'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN', ''),
'folderId' => env('GOOGLE_DRIVE_FOLDER_ID', ''),
]
],
Usage
Here are examples of how to use the methods provided by the package.
uploadFile
Upload a file to Google Drive.
use Tes\LaravelGoogleDriveStorage\GoogleDriveService; $file = $request->file('upload'); // Assuming this comes from a form $folderId = ''; // Optional $response = GoogleDriveService::uploadFile($file, $folderId); echo "File uploaded with ID: " . $response->id;
createFolder
Create a new folder in Google Drive.
use Tes\LaravelGoogleDriveStorage\GoogleDriveService; $folderName = 'New Folder'; $response = GoogleDriveService::createFolder($folderName); echo "Folder created with ID: " . $response['folderId'];
search
Search for files or folders in Google Drive by name.
use Tes\LaravelGoogleDriveStorage\GoogleDriveService; $searchName = 'example'; $files = GoogleDriveService::search($searchName, 'all'); // Can be 'files', 'folders', or 'all' foreach ($files as $file) { echo "Found file with ID: " . $file['id'] . " and name: " . $file['name'] . "\n"; }
listFilesInFolder
List files within a specific folder.
use Tes\LaravelGoogleDriveStorage\GoogleDriveService; $folderId = 'your_folder_id'; $files = GoogleDriveService::listFilesInFolder($folderId); foreach ($files as $file) { echo "File in folder with ID: " . $file['id'] . " and name: " . $file['name'] . "\n"; }
getFileMetadata
Retrieve metadata of a specific file.
use Tes\LaravelGoogleDriveStorage\GoogleDriveService; $fileId = 'your_file_id'; $metadata = GoogleDriveService::getFileMetadata($fileId); echo "File metadata:\n"; echo "ID: " . $metadata['id'] . "\n"; echo "Name: " . $metadata['name'] . "\n"; echo "MIME Type: " . $metadata['mimeType'] . "\n"; echo "Size: " . $metadata['size'] . "\n"; echo "Created Time: " . $metadata['createdTime'] . "\n"; echo "Modified Time: " . $metadata['modifiedTime'] . "\n";
updateFileMetadata
Update the metadata (e.g., name) of a specific file.
use Tes\LaravelGoogleDriveStorage\GoogleDriveService; $fileId = 'your_file_id'; $newName = 'Updated File Name'; $response = GoogleDriveService::updateFileMetadata($fileId, $newName); echo "File updated with ID: " . $response['id'] . " and new name: " . $response['name'];
download
Download a file from Google Drive.
use Tes\LaravelGoogleDriveStorage\GoogleDriveService; $path = 'path/to/your/file/on/drive'; $response = GoogleDriveService::download($path); // you got it!!
url
Get the URL of a file stored in Google Drive.
use Tes\LaravelGoogleDriveStorage\GoogleDriveService; $path = 'path/to/your/file/on/drive'; $url = GoogleDriveService::url($path); echo "File URL: " . $url; // Like This Format: https://drive.google.com/file/d/1jGhj2nX2MNbH5VPwe8SqTKSUu0U-S-VX/view?usp=sharing
delete
Delete a file from Google Drive.
use Tes\LaravelGoogleDriveStorage\GoogleDriveService; $path = 'path/to/your/file/on/drive'; $response = GoogleDriveService::delete($path); if ($response) { echo "File deleted successfully."; } else { echo "Failed to delete file."; }
License
This package is licensed under the MIT License. See the LICENSE file for more details.
tes/laravel-google-drive-storage 适用场景与选型建议
tes/laravel-google-drive-storage 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.88k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2024 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「filesystem」 「storage」 「laravel」 「google drive」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tes/laravel-google-drive-storage 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tes/laravel-google-drive-storage 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tes/laravel-google-drive-storage 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
A PHP class providing static methods for reading, writing, copying, moving, and deleting files and directories, MIME type detection, image size detection, and file permission management
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
The flysystem adapter for yandex disk rest api.
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
phpABLE file-system library
统计信息
- 总下载量: 2.88k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-03