laravel使用腾讯云cos存储对象保存文件

作者: dreamfly 分类: php 发布时间: 2020-08-18 13:03

安装依赖

composer require freyo/flysystem-qcloud-cos-v5

添加服务

修改config/app.php文件,添加cos服务

Freyo\Flysystem\QcloudCOSv5\ServiceProvider::class,

添加文件存储驱动

修改config/filesystems.php文件,添加cos配置

'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'),
    ],
],

添加配置

修改.env文件

COSV5_REGION=xxx
COSV5_APP_ID=xxx
COSV5_SECRET_ID=xxx
COSV5_SECRET_KEY=xxx
COSV5_TIMEOUT=xxx
COSV5_CONNECT_TIMEOUT=xxx
COSV5_BUCKET=xxx
COSV5_CDN=xxx
COSV5_SCHEME=xxx

编写调用存储代码

$filename = $this->getFileName($request->image);获取文件名

$FilePath = $request->image->getRealPath(); //获取文件临时存放位置

Storage::disk('cosv5')->put($filename, file_get_contents($FilePath)); //云存储文件

$request->image->move(base_path('public/images'), $filename);//本地保存文件

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

7条评论
  • Acousty

    2022年9月1日 09:27

    Along with this, we have appointed a team of diligent and dexterous professionals who carry out the trade activities buy cialis 10mg

  • Kebyecove

    2022年9月3日 13:44

    – Super Tadarise Tablets belongs to the group of phosphodiesterase inhibitors PDE 5 used to treat erectile dysfunction, Premature Ejaculation or impotence want to buy priligy in pakistan With potent CYP3A4 inhibitors such as indinavir, saquinavir, atazanavir Reyataz, Bristol-Myers Squibb , ketoconazole 400 mg, itraconazole 400 mg, and clarithromycin Biaxin, Abbott , doses of vardenafil 2

  • dwerbus

    2022年9月5日 11:56

    buy cialis online from india which otc male sexual enhancement pills contain viagra cialis But now she is sneaking observation, according to her own realm of flying light, since she can t see through each other

  • pacyImmaw

    2022年9月7日 14:17

    If anyone approaches, you should stop them as soon as possible in any case, you must protect the passage I opened, otherwise cheap cialis generic online No hassle, no worries

  • ensuece

    2022年9月10日 11:52

    erectzan risperidone side effects hair loss According to a 2006 report by the U. buy clomid

  • extedia

    2022年9月13日 14:02

    The diagnosis of hypogonadism relies on the combination of laboratory measurements of serum testosterone and clinical signs and symptoms of androgen deficiency. tamoxifen withdrawal symptoms

  • AnnoutFus

    2022年9月17日 04:58

    PID most commonly occurs through ascending infection, and much less commonly occurs through contiguous spread from other pelvic organs. doxycline hyclate 100mg purchase striatum 16S rRNA and rpoB genes were deposited KJ934779 to KJ934789, KM001910 to KM001914, KJ855309 to KJ855313, KR010627 to KR010645, KR020513 and KR020514.

发表评论

您的电子邮箱地址不会被公开。