当前位置:网站首页>laravel 使用腾讯云 COS5全教程
laravel 使用腾讯云 COS5全教程
2022-07-07 01:11:00 【生命不止、战斗不息】
laravel 使用腾讯云 COS5全教程
一 下载
首先第一步肯定是用composer把包安装下来,这里是laravel5.8版本的,所以我用的是cos5
composer require freyo/flysystem-qcloud-cos-v5二 配置
1、在config/app.php进行添加
'providers' => [
// ...
Freyo\Flysystem\QcloudCOSv5\ServiceProvider::class,
]
2、配置config/filesystems.php:
'disks'=>[
// ...
'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),
],
],
3、配置.env: 注意:把\\后面的都去掉
COSV5_APP_ID=//控制台可以看见的appid
COSV5_SECRET_ID=//控制台可以看见的SecretId
COSV5_SECRET_KEY=//控制台可以看见的SecretKey
COSV5_TIMEOUT=60
COSV5_CONNECT_TIMEOUT=60
COSV5_BUCKET=
COSV5_REGION=ap-guangzhou//所属地域,这里如果配置了就不用在config里面配置
COSV5_CDN= #https://{your-bucket-name}-{your-app-id}.file.myqcloud.com
COSV5_SCHEME=https
COSV5_READ_FROM_CDN=false
4、如果出现如下报错
laravel Driver [] is not supported.
请在cmd中执行以下操作
php artisan config:cache5、获取秘钥网址:腾讯秘钥获取地址
三 上传文件
public function upload_file(Request $request)
{
//对文件进行判断
$file = $request->file('file');
if(empty($file))
{
return json_encode(['msg'=>'文件不能为空','status'=>0]);
}
//上传文件
$disk = Storage::disk('cosv5');
$file_content = $disk -> put('video_class',$file);//第一个参数是你储存桶里想要放置文件的路径,第二个参数是文件对象
$file_url = $disk->url($file_content);//获取到文件的线上地址
return json_encode(['msg'=>'上传成功','status'=>1,'data'=>['file_url' => $file_url]]);//返回参数
}


边栏推荐
- [daily training -- Tencent selected 50] 235 Nearest common ancestor of binary search tree
- Jcmd of JVM command: multifunctional command line
- 一个简单的代数问题的求解
- 原生小程序 之 input切换 text与password类型
- Bat instruction processing details
- POI excel export, one of my template methods
- Go language learning notes - Gorm use - Gorm processing errors | web framework gin (10)
- @pathvariable 和 @Requestparam的详细区别
- Deep clustering: joint optimization of depth representation learning and clustering
- If you don't know these four caching modes, dare you say you understand caching?
猜你喜欢

Three level menu data implementation, nested three-level menu data

《ClickHouse原理解析与应用实践》读书笔记(6)

Check point: the core element for enterprises to deploy zero trust network (ztna)

Introduction to the extension implementation of SAP Spartacus checkout process

Financial risk control practice - decision tree rule mining template

JVM命令之 jstack:打印JVM中线程快照

VScode进行代码补全

Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL | Web框架Gin(九)
![C. colonne Swapping [tri + Simulation]](/img/0e/64d17980d3ec0051cdfb5fdb34e119.png)
C. colonne Swapping [tri + Simulation]

驱动开发中platform设备驱动架构详解
随机推荐
What EDA companies are there in China?
生活中的开销,怎么记账合适
云加速,帮助您有效解决攻击问题!
JVM监控及诊断工具-命令行篇
老板总问我进展,是不信任我吗?(你觉得呢)
Peripheral driver library development notes 43: GPIO simulation SPI driver
cf:C. Column Swapping【排序 + 模拟】
[InstallShield] Introduction
PowerPivot - DAX (function)
Interview questions and salary and welfare of Shanghai byte
Interview skills of software testing
Flask1.1.4 Werkzeug1.0.1 源碼分析:啟動流程
Bbox regression loss function in target detection -l2, smooth L1, IOU, giou, Diou, ciou, focal eiou, alpha IOU, Siou
MFC BMP sets the resolution of bitmap, DPI is 600 points, and gdiplus generates labels
Type de texte de commutation d'entrée et de mot de passe de l'applet natif
JVM命令之 jstat:查看JVM统计信息
成为资深IC设计工程师的十个阶段,现在的你在哪个阶段 ?
C. colonne Swapping [tri + Simulation]
POI excel export, one of my template methods
Go language learning notes - Gorm use - Gorm processing errors | web framework gin (10)