定制 freyo/flysystem-qcloud-cos-v4 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

freyo/flysystem-qcloud-cos-v4

Composer 安装命令:

composer require freyo/flysystem-qcloud-cos-v4

包简介

Flysystem Adapter for Tencent Qcloud COS SDK V4

README 文档

README

Software License Build Status Coverage Status Quality Score Packagist Version Total Downloads

This is a Flysystem adapter for the qcloud-cos-sdk-php v4.

腾讯云COS对象存储 V4

Attention

if you are a new registered user(after October 2016), v4 should be used.

2016年10月以后新注册的用户默认使用V4版本

if you have used COS before October 2016, v3 can continue to use.

2016年10月之前使用COS的用户可以继续使用V3版本

Installation

composer require freyo/flysystem-qcloud-cos-v4

Bootstrap

<?php
use Freyo\Flysystem\QcloudCOSv4\Adapter;
use League\Flysystem\Filesystem;

include __DIR__ . '/vendor/autoload.php';

$config = [
    'protocol' => 'http',
    'domain' => 'your-domain',
    'app_id' => 'your-app-id',
    'secret_id' => 'your-secret-id',
    'secret_key' => 'your-secret-key',
    'timeout' => 60,
    'bucket' => 'your-bucket-name',
    'region' => 'gz',
    'debug' => false,
];

$adapter = new Adapter($config);
$filesystem = new Filesystem($adapter);

API

bool $flysystem->write('file.md', 'contents');

bool $flysystem->writeStream('file.md', fopen('path/to/your/local/file.jpg', 'r'));

bool $flysystem->update('file.md', 'new contents');

bool $flysystem->updateStram('file.md', fopen('path/to/your/local/file.jpg', 'r'));

bool $flysystem->rename('foo.md', 'bar.md');

bool $flysystem->copy('foo.md', 'foo2.md');

bool $flysystem->delete('file.md');

bool $flysystem->has('file.md');

string|false $flysystem->read('file.md');

array $flysystem->listContents();

array $flysystem->getMetadata('file.md');

int $flysystem->getSize('file.md');

string $flysystem->getUrl('file.md'); 

string $flysystem->getTemporaryUrl('file.md', date_create('2018-12-31 18:12:31')); 

string $flysystem->getMimetype('file.md');

int $flysystem->getTimestamp('file.md');

string $flysystem->getVisibility('file.md');

bool $flysystem->setVisibility('file.md', 'public'); //or 'private'

Full API documentation.

Use in Laravel

Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

  1. Register the service provider in config/app.php:
'providers' => [
  // ...
  Freyo\Flysystem\QcloudCOSv4\ServiceProvider::class,
]
  1. Configure config/filesystems.php:
'disks'=>[
    // ...
    'cosv4' => [
        'driver' => 'cosv4',
        'protocol' => env('COSV4_PROTOCOL', 'http'),
        'domain' => env('COSV4_DOMAIN'),
        'app_id' => env('COSV4_APP_ID'),
        'secret_id' => env('COSV4_SECRET_ID'),
        'secret_key' => env('COSV4_SECRET_KEY'),
        'timeout' => env('COSV4_TIMEOUT', 60),
        'bucket' => env('COSV4_BUCKET'),
        'region' => env('COSV4_REGION', 'gz'),
        'debug' => env('COSV4_DEBUG', false),
    ],
],

Use in Lumen

  1. Add the following code to your bootstrap/app.php:
$app->singleton('filesystem', function ($app) {
    $app->alias('filesystem', Illuminate\Contracts\Filesystem\Factory::class);
    return $app->loadComponent(
        'filesystems',
        Illuminate\Filesystem\FilesystemServiceProvider::class,
        'filesystem'
    );
});
  1. And this:
$app->register(Freyo\Flysystem\QcloudCOSv4\ServiceProvider::class);
  1. Configure .env:
COSV4_PROTOCOL=http
COSV4_DOMAIN=
COSV4_APP_ID=
COSV4_SECRET_ID=
COSV4_SECRET_KEY=
COSV4_TIMEOUT=60
COSV4_BUCKET=
COSV4_REGION=gz
COSV4_DEBUG=true

Usage

$disk = Storage::disk('cosv4');

// create a file
$disk->put('avatars/1', $fileContents);

// check if a file exists
$exists = $disk->has('file.jpg');

// get timestamp
$time = $disk->lastModified('file1.jpg');

// copy a file
$disk->copy('old/file1.jpg', 'new/file1.jpg');

// move a file
$disk->move('old/file1.jpg', 'new/file1.jpg');

// get file contents
$contents = $disk->read('folder/my_file.txt');

// get url
$url = $disk->url('new/file1.jpg');
$temporaryUrl = $disk->temporaryUrl('new/file1.jpg', Carbon::now()->addMinutes(5));

// create a file from remote(plugin support)
$disk->putRemoteFile('avatars/1', 'http://example.org/avatar.jpg');
$disk->putRemoteFileAs('avatars/1', 'http://example.org/avatar.jpg', 'file1.jpg');

Full API documentation.

Region

地区 区域表示
华南 gz
华北 tj
华东 sh

freyo/flysystem-qcloud-cos-v4 适用场景与选型建议

freyo/flysystem-qcloud-cos-v4 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.72k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2017 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「qcloud」 「flysystem-adapter」 「qcloud-cos」 「qcloud-sdk」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 freyo/flysystem-qcloud-cos-v4 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 freyo/flysystem-qcloud-cos-v4 我们能提供哪些服务?
定制开发 / 二次开发

基于 freyo/flysystem-qcloud-cos-v4 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.72k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 8
  • 依赖项目数: 1
  • 推荐数: 1

GitHub 信息

  • Stars: 14
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-21