shawnl/tencent-cos

Tencent COS SDK wrapper for PHP with Laravel support

Maintainers

Details

gitee.com/lsz_mo/tencent-cos.git

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

pkg:composer/shawnl/tencent-cos

v1.0.1 2025-11-10 09:30 UTC

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