PHP code example of jackillll / laravel-filament-client-upload-cos
1. Go to this page and download the library: Download jackillll/laravel-filament-client-upload-cos library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jackillll / laravel-filament-client-upload-cos example snippets
use Filament\Forms\Components\FileUpload;
FileUpload::make('avatar')
->cosUpload() // 启用 COS 直传
->acceptedFileTypes(['image/jpeg', 'image/png'])
->maxSize(5120); // 5MB
FileUpload::make('document')
->cosUpload('documents/') // 自定义上传路径
->acceptedFileTypes(['application/pdf']);
FileUpload::make('image')
->cosUpload()
->cosUploadConfig([
'max_file_size' => 2097152, // 2MB
'allowed_extensions' => ['jpg', 'png', 'gif'],
]);
FileUpload::make('file')
->cosUpload()
->cosUploadSuccess(function ($file) {
// 处理上传成功后的逻辑
Log::info('File uploaded successfully', ['file' => $file]);
});
use YourVendor\FilamentCosUpload\Components\FileUpload;
FileUpload::make('attachment')
->cosUpload('attachments/')
->cosUploadSuccess(function ($file) {
// 自定义处理逻辑
});
return [
// 腾讯云 COS 配置
'secret_id' => env('COS_SECRET_ID'),
'secret_key' => env('COS_SECRET_KEY'),
'region' => env('COS_REGION', 'ap-beijing'),
'bucket' => env('COS_BUCKET'),
'domain' => env('COS_DOMAIN'),
// 上传配置
'max_file_size' => env('COS_MAX_FILE_SIZE', 10485760), // 10MB
'allowed_extensions' => ['jpg', 'jpeg', 'png', 'gif', 'pdf', 'doc', 'docx'],
'upload_path' => env('COS_UPLOAD_PATH', 'uploads/'),
// 安全配置
'signature_expires' => 3600, // 1小时
'callback_url' => env('COS_CALLBACK_URL'),
];
bash
php artisan vendor:publish --tag="filament-cos-upload-config"