当前位置:网站首页>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]]);//返回参数
}
边栏推荐
- JVM命令之- jmap:导出内存映像文件&内存使用情况
- Mac version PHP installed Xdebug environment (M1 version)
- New Year Fireworks code plus copy, are you sure you don't want to have a look
- 测试开发基础,教你做一个完整功能的Web平台之环境准备
- Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
- 成为资深IC设计工程师的十个阶段,现在的你在哪个阶段 ?
- [InstallShield] Introduction
- Chain storage of stack
- 【FPGA教程案例14】基于vivado核的FIR滤波器设计与实现
- Question 102: sequence traversal of binary tree
猜你喜欢
PTA 天梯赛练习题集 L2-004 搜索树判断
jvm命令之 jcmd:多功能命令行
数字IC面试总结(大厂面试经验分享)
Interview skills of software testing
[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core
关于STC单片机“假死”状态的判别
Peripheral driver library development notes 43: GPIO simulation SPI driver
SAP ABAP BDC (batch data communication) -018
@pathvariable 和 @Requestparam的详细区别
【FPGA教程案例14】基于vivado核的FIR滤波器设计与实现
随机推荐
Sequential storage of stacks
Why does the data center need a set of infrastructure visual management system
JVM命令之 jinfo:实时查看和修改JVM配置参数
JVM监控及诊断工具-命令行篇
[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core
Flask 1.1.4 werkzeug1.0.1 analyse du code source: processus de démarrage
Digital IC interview summary (interview experience sharing of large manufacturers)
mac版php装xdebug环境(m1版)
JVM命令之 jstack:打印JVM中线程快照
Chain storage of stack
老板总问我进展,是不信任我吗?(你觉得呢)
693. 行程排序
Solve pod install error: FFI is an incompatible architecture
Introduction to the extension implementation of SAP Spartacus checkout process
What is make makefile cmake qmake and what is the difference?
[daily training -- Tencent selected 50] 235 Nearest common ancestor of binary search tree
What EDA companies are there in China?
JVM monitoring and diagnostic tools - command line
Opensergo is about to release v1alpha1, which will enrich the service governance capabilities of the full link heterogeneous architecture
Type de texte de commutation d'entrée et de mot de passe de l'applet natif