当前位置:网站首页>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:cache
5、获取秘钥网址:腾讯秘钥获取地址
三 上传文件
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]]);//返回参数
}
边栏推荐
- Flask1.1.4 Werkzeug1.0.1 源码分析:启动流程
- Go语学习笔记 - gorm使用 - gorm处理错误 | Web框架Gin(十)
- Bypass open_ basedir
- JVM命令之- jmap:导出内存映像文件&内存使用情况
- 苹果cms V10模板/MXone Pro自适应影视电影网站模板
- PTA ladder game exercise set l2-002 linked list de duplication
- Cloud acceleration helps you effectively solve attack problems!
- Input of native applet switches between text and password types
- 10W word segmentation searches per second, the product manager raised another demand!!! (Collection)
- CMD permanently delete specified folders and files
猜你喜欢
Introduction to the extension implementation of SAP Spartacus checkout process
Introduction to yarn (one article is enough)
[云原生]微服务架构是什么?
jvm命令之 jcmd:多功能命令行
Detailed explanation of platform device driver architecture in driver development
DC-7靶机
mac版php装xdebug环境(m1版)
Jstat of JVM command: View JVM statistics
为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
Convert numbers to string strings (to_string()) convert strings to int sharp tools stoi();
随机推荐
ML's shap: Based on the adult census income binary prediction data set (whether the predicted annual income exceeds 50K), use the shap decision diagram combined with the lightgbm model to realize the
改变ui组件原有样式
On the discrimination of "fake death" state of STC single chip microcomputer
Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
软件测试知识储备:关于「登录安全」的基础知识,你了解多少?
EMMC print cqhci: timeout for tag 10 prompt analysis and solution
产业金融3.0:“疏通血管”的金融科技
搞懂fastjson 对泛型的反序列化原理
Interview skills of software testing
k8s运行oracle
Bypass open_ basedir
成为资深IC设计工程师的十个阶段,现在的你在哪个阶段 ?
测试开发基础,教你做一个完整功能的Web平台之环境准备
数字IC面试总结(大厂面试经验分享)
《ClickHouse原理解析与应用实践》读书笔记(6)
Convert numbers to string strings (to_string()) convert strings to int sharp tools stoi();
Go language learning notes - Gorm use - native SQL, named parameters, rows, tosql | web framework gin (IX)
Value range of various datetimes in SQL Server 2008
职场经历反馈给初入职场的程序员
Chain storage of stack