Coder Social home page Coder Social logo

freyo / flysystem-qcloud-cos-v5 Goto Github PK

View Code? Open in Web Editor NEW
156.0 5.0 23.0 168 KB

💾 Flysystem Adapter for Tencent Cloud COS V5

Home Page: https://intl.cloud.tencent.com/product/cos?lang=en

License: MIT License

PHP 100.00%
flysystem-adapter flysystem-qcloud-cos cos laravel php

flysystem-qcloud-cos-v5's Introduction

Installation

Support Laravel/Lumen 5.x/6.x/7.x/8.x

composer require "freyo/flysystem-qcloud-cos-v5:^2.0" -vvv

Bootstrap

<?php
use Freyo\Flysystem\QcloudCOSv5\Adapter;
use League\Flysystem\Filesystem;
use Qcloud\Cos\Client;

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

$config = [
    'region'          => 'ap-guangzhou',
    'credentials'     => [
        'appId'     => 'your-app-id',
        'secretId'  => 'your-secret-id',
        'secretKey' => 'your-secret-key',
        'token'     => null,
    ],
    'timeout'         => 60,
    'connect_timeout' => 60,
    'bucket'          => 'your-bucket-name',
    'cdn'             => '',
    'scheme'          => 'https',
    'read_from_cdn'   => false,
    'cdn_key'         => '',
    'encrypt'         => false,
];

$client     = new Client($config);
$adapter    = new Adapter($client, $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', 'default'

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\QcloudCOSv5\ServiceProvider::class,
]
  1. Configure 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'),
              'token'     => env('COSV5_TOKEN'),
          ],
          '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),
          'cdn_key'         => env('COSV5_CDN_KEY'),
          'encrypt'         => env('COSV5_ENCRYPT', false),
    ],
],
  1. Configure .env:
COSV5_APP_ID=
COSV5_SECRET_ID=
COSV5_SECRET_KEY=
COSV5_TOKEN=null
COSV5_TIMEOUT=60
COSV5_CONNECT_TIMEOUT=60
COSV5_BUCKET=
COSV5_REGION=ap-guangzhou
COSV5_CDN=
COSV5_SCHEME=https
COSV5_READ_FROM_CDN=false
COSV5_CDN_KEY=
COSV5_ENCRYPT=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\QcloudCOSv5\ServiceProvider::class);
  1. Configure .env:
COSV5_APP_ID=
COSV5_SECRET_ID=
COSV5_SECRET_KEY=
COSV5_TOKEN=null
COSV5_TIMEOUT=60
COSV5_CONNECT_TIMEOUT=60
COSV5_BUCKET=
COSV5_REGION=ap-guangzhou
COSV5_CDN=
COSV5_SCHEME=https
COSV5_READ_FROM_CDN=false
COSV5_CDN_KEY=
COSV5_ENCRYPT=false

Usage

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

// 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)
$disk->putRemoteFile('avatars/1', 'http://example.org/avatar.jpg');
$disk->putRemoteFileAs('avatars/1', 'http://example.org/avatar.jpg', 'file1.jpg');

// refresh cdn cache(plugin)
$disk->cdn()->refreshUrl(['http://your-cdn-host/path/to/avatar.jpg']);
$disk->cdn()->refreshDir(['http://your-cdn-host/path/to/']);
$disk->cdn()->pushUrl(['http://your-cdn-host/path/to/avatar.jpg']);
$disk->cdn()->refreshOverseaUrl(['http://your-cdn-host/path/to/avatar.jpg']);
$disk->cdn()->refreshOverseaDir(['http://your-cdn-host/path/to/']);
$disk->cdn()->pushOverseaUrl(['http://your-cdn-host/path/to/avatar.jpg']);

// cdn url signature(plugin)
$url = 'http://www.test.com/1.mp4';
$disk->cdn()->signatureA($url, $key = null, $timestamp = null, $random = null, $signName = 'sign');
$disk->cdn()->signatureB($url, $key = null, $timestamp = null);
$disk->cdn()->signatureC($url, $key = null, $timestamp = null);
$disk->cdn()->signatureD($url, $key = null, $timestamp = null, $signName = 'sign', $timeName = 't');

// tencent captcha(plugin)
$disk->tcaptcha($aid, $appSecretKey)->verify($ticket, $randStr, $userIP);

// get federation token(plugin)
$disk->getFederationToken($path = '*', $seconds = 7200, Closure $customPolicy = null, $name = 'cos')
$disk->getFederationTokenV3($path = '*', $seconds = 7200, Closure $customPolicy = null, $name = 'cos')

// tencent image process(plugin)
$disk->cloudInfinite()->imageProcess($objectKey, array $picOperations);
$disk->cloudInfinite()->contentRecognition($objectKey, array $contentRecognition);

Full API documentation.

Regions & Endpoints

Official Documentation

License

The MIT License (MIT). Please see License File for more information.

FOSSA Status

flysystem-qcloud-cos-v5's People

Contributors

fossabot avatar freyo avatar kuri-su avatar lddsb avatar liyaojian avatar tabll avatar xiaohuilam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

flysystem-qcloud-cos-v5's Issues

文件夹无法删除

文件夹无法删除是什么原因。

可以创建文件和文件夹,也可以删除文件,就是按照同样的方式传入PATH删除文件夹失败。

提示
strpbrk() expects parameter 1 to be string, array given

qcloud/cos-sdk-v5 升级v1.3.4 以后,在Laravel中调用 get 或 read方法会报错

qcloud/cos-sdk-v5 更新了v1.3.4,似乎是把Guzzle从3升级到了6,这在目前的最新版 flysystem-qcloud-cos-v5 (v1.4.3)中会导致报错:

PHP Error:  Call to undefined method GuzzleHttp/Command/Result::get() in /var/www/************/vendor/freyo/flysystem-qcloud-cos-v5/src/Adapter.php on line 315

Adapter.php 中使用了 $response->get('Body') 来获取请求到的文件,而在v1.3.4 的 qcloud/cos-sdk-v5 中,这里拿到的 $response 已经是 GuzzleHttp\Command\Result Object 了,它没有get方法。

代理设置有问题

在配置里面设置了代理
'proxy' => '****',

上传及下载没问题,getFederationTokenV3代理不生效

image

加上代理则正常访问

url获取线上地址后面加了很多参数

使用Storage->url(xxx),获取线上地址,地址后面怎么加了很多参数
url?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDLh2UwFSdkiU6bv1ua3IK8k9KGxPcaKq6%26q-sign-time%3D1641615929%3B1641617789%26q-key-time%3D1641615929%3B1641617789%26q-header-list%3Dhost%26q-url-param-list%3D%26q-signature%3Dc7e540bb80879a1d2c6f05b39f8ab91e72a40c9d&
可以去掉这些参数?

GetFederationToken插件没有默认启用?

你好
我刚开始用这个库。想要用这个实现生成临时上传凭证,让小程序直接上传文件到cos上。
我发现代码中已经实现了getFederationToken方法,然而并没有默认启用。
需要在需要调用getFederationToken的地方,手动启用插件。

$disk->addPlugin(new \Freyo\Flysystem\QcloudCOSv5\Plugins\GetFederationToken());

方可调用getFederationToken方法生成上传凭证。

$token = $disk->getFederationToken();

是否有计划默认启用getFederationToken
谢谢

请支持一下laravel8 谢谢!安装提示guzzlehttp 低于7.2.0 ,谢谢你!

` Problem 1
- Installation request for guzzlehttp/guzzle (locked at 7.2.0, required as ^7.0.1) -> satisfiable by guzzlehttp/guzzle[7.2.0].
- freyo/flysystem-qcloud-cos-v5 2.0.0 requires guzzlehttp/guzzle ~6.0 -> satisfiable by guzzlehttp/guzzle[6.5.x-dev].
- freyo/flysystem-qcloud-cos-v5 2.0.1 requires guzzlehttp/guzzle ~6.0 -> satisfiable by guzzlehttp/guzzle[6.5.x-dev].
- freyo/flysystem-qcloud-cos-v5 2.0.2 requires guzzlehttp/guzzle ~6.0 -> satisfiable by guzzlehttp/guzzle[6.5.x-dev].
- freyo/flysystem-qcloud-cos-v5 2.0.3 requires guzzlehttp/guzzle ~6.0 -> satisfiable by guzzlehttp/guzzle[6.5.x-dev].
- freyo/flysystem-qcloud-cos-v5 2.1.0 requires guzzlehttp/guzzle ~6.0 -> satisfiable by guzzlehttp/guzzle[6.5.x-dev].
- Conclusion: don't install guzzlehttp/guzzle 6.5.x-dev
- Installation request for freyo/flysystem-qcloud-cos-v5 ^2.0 -> satisfiable by freyo/flysystem-qcloud-cos-v5[2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.1.0].

Installation failed, reverting ./composer.json to its original content.
`

undefined function GuzzleHttp\Psr7\stream_for()

[2021-08-17 19:17:31] local.ERROR: Call to undefined function GuzzleHttp\Psr7\stream_for() {"userId":1,"exception":"[object] (Error(code: 0): Call to undefined function GuzzleHttp\Psr7\stream_for() at /var/www/admin/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Client.php:215)
[stacktrace]
#0 /var/www/admin/vendor/freyo/flysystem-qcloud-cos-v5/src/Adapter.php(202): Qcloud\Cos\Client->upload('jkt-1305459411', 'WX20210817-1854...', '\x89PNG

\x1A\

升级到 qcloud/cos-sdk-v5: 2.*

Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.

看了一下,package.json 还用的是 "qcloud/cos-sdk-v5": "1.3.3",

可以升级一下吗?现在最新的是 2.*

提示 Trying to access array offset on value of type bool 错误

提示 Trying to access array offset on value of type bool 错误

  • "laravel/framework": "^8.75",
  • "freyo/flysystem-qcloud-cos-v5": "^2.2",
ErrorException: Trying to access array offset on value of type bool in file vendor/qcloud/cos-sdk-v5/src/Signature.php on line 99

#0 vendor/qcloud/cos-sdk-v5/src/Signature.php(99): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Trying to acces...', '/Users/chao/w14...', 99, Array)
#1 vendor/qcloud/cos-sdk-v5/src/Signature.php(64): Qcloud\Cos\Signature->createAuthorization(Object(GuzzleHttp\Psr7\Request))
#2 vendor/qcloud/cos-sdk-v5/src/SignatureMiddleware.php(21): Qcloud\Cos\Signature->signRequest(Object(GuzzleHttp\Psr7\Request))
#3 vendor/guzzlehttp/guzzle/src/Middleware.php(240): Qcloud\Cos\SignatureMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#4 vendor/guzzlehttp/guzzle/src/RetryMiddleware.php(67): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#5 vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(64): GuzzleHttp\RetryMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#6 vendor/guzzlehttp/guzzle/src/Middleware.php(31): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#7 vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(55): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#8 vendor/guzzlehttp/guzzle/src/Middleware.php(63): GuzzleHttp\RedirectMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#9 vendor/guzzlehttp/guzzle/src/HandlerStack.php(75): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#10 vendor/guzzlehttp/guzzle/src/Client.php(331): GuzzleHttp\HandlerStack->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#11 vendor/guzzlehttp/guzzle/src/Client.php(107): GuzzleHttp\Client->transfer(Object(GuzzleHttp\Psr7\Request), Array)
#12 vendor/guzzlehttp/command/src/ServiceClient.php(173): GuzzleHttp\Client->sendAsync(Object(GuzzleHttp\Psr7\Request), Array)
#13 [internal function]: GuzzleHttp\Command\ServiceClient->GuzzleHttp\Command\{closure}()
#14 vendor/guzzlehttp/promises/src/Coroutine.php(71): Generator->current()
#15 vendor/guzzlehttp/promises/src/Coroutine.php(86): GuzzleHttp\Promise\Coroutine->__construct(Object(Closure))
#16 vendor/guzzlehttp/promises/src/functions.php(362): GuzzleHttp\Promise\Coroutine::of(Object(Closure))
#17 vendor/guzzlehttp/command/src/ServiceClient.php(181): GuzzleHttp\Promise\coroutine(Object(Closure))
#18 vendor/guzzlehttp/guzzle-services/src/Handler/ValidatedDescriptionHandler.php(79): GuzzleHttp\Command\ServiceClient->GuzzleHttp\Command\{closure}(Object(GuzzleHttp\Command\Command))
#19 vendor/guzzlehttp/command/src/ServiceClient.php(85): GuzzleHttp\Command\Guzzle\Handler\ValidatedDescriptionHandler->GuzzleHttp\Command\Guzzle\Handler\{closure}(Object(GuzzleHttp\Command\Command))
#20 vendor/guzzlehttp/command/src/ServiceClient.php(77): GuzzleHttp\Command\ServiceClient->executeAsync(Object(GuzzleHttp\Command\Command))
#21 vendor/guzzlehttp/command/src/ServiceClient.php(153): GuzzleHttp\Command\ServiceClient->execute(Object(GuzzleHttp\Command\Command))
#22 vendor/qcloud/cos-sdk-v5/src/Client.php(296): GuzzleHttp\Command\ServiceClient->__call('PutObject', Array)
#23 vendor/qcloud/cos-sdk-v5/src/Client.php(348): Qcloud\Cos\Client->__call('putObject', Array)

lumen 5.8报错

local.ERROR: InvalidArgumentException: Driver [] is not supported.

安装的都是最新版
使用Storage::disk('cosv5')报错

最近用了您的getFederationToken插件获取临时token

$disk->getFederationToken();
获取后,发现授权一直不成功,后来才知道是policy中的resource没有个getFderationToken的参数中指定位置,如果像源码代码中使用/结尾是不行的,后面是需要手动指定文件的存储位置,不指定的话则不分配,也就是不提供位置进行存储。 后来使用了$disk->getFederationToken('*'); 才解决了问题

Guzzle except error

Its working with the fotos, like jpg , jpeg ,png ...
But when i try to upload video file like *.mp4
Guzzle except error: Invalid resource type

getUrl时文件无后缀

$disk = Storage::disk('cosv5');
//$exists = $disk->put('/'.md5_file(public_path().'\lg.jpg').'.jpg',$fileContents);

$url = $disk->url('/'.md5_file(public_path().'\lg.jpg'));

$temporaryUrl = $disk->temporaryUrl('/'.md5_file(public_path().'\lg.jpg'), Carbon::now()->addMinutes(5));

var_dump($url);

echo '<br/>';

var_dump($temporaryUrl);

上面是我的测试代码

string(85) "https://test-1258858940.cos.ap-shanghai.myqcloud.com/89babd0924649ca463ff4988f7ce4680" string(341) "https://test-1258858940.cos.ap-shanghai.myqcloud.com/89babd0924649ca463ff4988f7ce4680?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDKQQFpASApGSTJILWmna8VhiU4QYRiYpw%26q-sign-time%3D1554363195%3B1554363555%26q-key-time%3D1554363195%3B1554363555%26q-header-list%3Dhost%26q-url-param-list%3D%26q-signature%3D6a17711eb0db254a4ec67d8699acfdae7bac3fff"

两个Url中都没有文件后缀,看看是我的姿势不对吗?

url获取的上传地址后面可以不加后缀吗

图片链接后面的参数信息
“?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDLh2UwFSdkiU6bv1ua3IK8k9KGxPcaKq6%26q-sign-time%3D1641700054%3B1641701914%26q-key-time%3D1641700054%3B1641701914%26q-header-list%3Dhost%26q-url-param-list%3D%26q-signature%3D934baaff9a2ae28bb29518ba84a5688f61d56168&
是不是可以去掉

When to support larravel10?

Class "League\Flysystem\Adapter\AbstractAdapter" not found ,
/vendor/freyo/flysystem-qcloud-cos-v5/src/Adapter.php => 17

Laravel 5.5 调用 copy move 方法返回出错

     {
        'message': '403 Forbidden (Request-ID: NWIzNGEyZjZfNjZhYTk0MGFfOGIwZl85NDc5YTE=)',
        'status_code': 500,
        'debug': {
          'line': 57,
          'file': '/home/vagrant/Projects/InteractApi/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/ExceptionListener.php',
          'class': 'Qcloud\\Cos\\Exception\\ServiceResponseException'
        }
      }

错误信息大致如上。

$disk = Storage::disk('cosv5');
$disk->copy('1.txt', '2.txt');

我是这样子调用的 但是返回以上的错误信息。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.