我们可以装静态文件图片视频上传到腾讯的cos中
可以起到加速访问的作用
在laravel中如何实现
首先安装
`composer require freyo/flysystem-qcloud-cos-v5`
然后配置
```
config.php
Freyo\Flysystem\QcloudCOSv5\ServiceProvider::class,
filesystems.php
'cosv5' => [
'driver' => 'cosv5',
//后面是控制台储存桶里设置的所属地域
'region' => env('COSV5_REGION', 'ap-guangzhou'),
'credentials' => [
'appId' => env('COSV5_APP_ID'),
'secretId' => env('COSV5_SECRET_ID'),
'secretKey' => env('COSV5_SECRET_KEY'),
],
'timeout' => env('COSV5_TIMEOUT', 60),
'connect_timeout' => env('COSV5_CONNECT_TIMEOUT', 60),
'bucket' => env('COSV5_BUCKET'),
'cdn' => env('COSV5_CDN'),
'scheme' => env('COSV5_SCHEME', 'https'),
'read_from_cdn' => env('COSV5_READ_FROM_CDN', false),
],
```
.env配置文件
```
COSV5_APP_ID=1253385472
## cos5的配置SECRET_ID
COSV5_SECRET_ID=AKIDd5IFvMcteZEdm3D6pIpBML4Ys0tWF0kG
##cos5的配置SECRET_key
COSV5_SECRET_KEY=PfniOp1yfAWcT4ScXDdrtfCTuFkz1mHX
COSV5_TIMEOUT=60
COSV5_CONNECT_TIMEOUT=60
COSV5_BUCKET=software-1253385472
COSV5_REGION=ap-shanghai
COSV5_CDN=https://edu-125730568.cos.ap-guangzhou.myqcloud.com
COSV5_SCHEME=https
COSV5_READ_FROM_CDN=false
```
然后是controller中操作
```
file('file');
//上传文件
$disk = Storage::disk('cosv5');
//参数1:储存桶里想要放置文件的路径,参数2:文件对象
$dir = date('Ymd');
$fileContent = $disk->put($dir,$file);
echo "
";
print_r($disk->getMetadata($fileContent));
echo $disk->url($fileContent);
echo "
";
echo $disk->size($fileContent);
echo "
";
echo $disk->mimetype($fileContent);
}
}
?>
```