shawnl / tencent-cos
Tencent COS SDK wrapper for PHP with Laravel support
v1.0.1
2025-11-10 09:30 UTC
Requires
- php: ^7.4|^8.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
- qcloud/cos-sdk-v5: ^2.0
Requires (Dev)
- orchestra/testbench: ^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.0
This package is not auto-updated.
Last update: 2025-11-10 09:31:35 UTC
README
This package provides a Tencent Cloud COS (Cloud Object Storage) adapter for Laravel's filesystem.
Installation
composer require shawnl/tencent-cos
Configuration
Add the following configuration to your config/filesystems.php file:
'cos' => [
'driver' => 'cos',
'region' => env('COS_DEFAULT_REGION'),
'credentials' => [
'secret_id' => env('COS_SECRET_ID'),
'secret_key' => env('COS_SECRET_KEY'),
],
'bucket' => env('COS_DEFAULT_BUCKET'),
'cdn_domain' => env('COS_DEFAULT_CDN_DOMAIN'),
],
Then add the following environment variables to your .env file:
COS_DEFAULT_REGION=your-region
COS_SECRET_ID=your-secret-id
COS_SECRET_KEY=your-secret-key
COS_DEFAULT_BUCKET=your-bucket
COS_DEFAULT_CDN_DOMAIN= https://your-cdn-domain.com
Usage
Using Laravel's Storage Facade
// Upload a file
Storage::disk('cos')->put('path/to/file.jpg', $fileContents);
// Get file URL
$url = Storage::disk('cos')->url('path/to/file.jpg');
// Delete a file
Storage::disk('cos')->delete('path/to/file.jpg');
Using the TencentCosService
use Trae\TencentCos\TencentCosService;
$cosService = app('tencent-cos');
// Upload file
$result = $cosService->upload($request->file('image'));
// Delete file
$cosService->delete('path/to/file.jpg');
License
MIT