Coder Social home page Coder Social logo

laravel-filesystem-qiniu's Introduction

Laravel filesystem Qiniu

Qiniu storage for Laravel based on overtrue/flysystem-qiniu.

Sponsor me

Requirement

  • Laravel >= 9.0

Installation

$ composer require "overtrue/laravel-filesystem-qiniu"

Configuration

  1. After installing the library, register the Overtrue\LaravelFilesystem\Qiniu\QiniuStorageServiceProvider in your config/app.php file:
'providers' => [
    // Other service providers...
    Overtrue\LaravelFilesystem\Qiniu\QiniuStorageServiceProvider::class,
],
  1. Add a new disk to your config/filesystems.php config:
<?php

return [
   'disks' => [
        //...
        'qiniu' => [
           'driver'     => 'qiniu',
           'access_key' => env('QINIU_ACCESS_KEY', 'xxxxxxxxxxxxxxxx'),
           'secret_key' => env('QINIU_SECRET_KEY', 'xxxxxxxxxxxxxxxx'),
           'bucket'     => env('QINIU_BUCKET', 'test'),
           'domain'     => env('QINIU_DOMAIN', 'xxx.clouddn.com'), // or host: https://xxxx.clouddn.com
        ],
        //...
    ]
];

Usage

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

// create a file
$disk->put('avatars/filename.jpg', $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');

// fetch url content
$file = $disk->getAdapter()->fetch('folder/save_as.txt', $fromUrl);

// get file url
$url = $disk->getAdapter()->getUrl('folder/my_file.txt');

// get file upload token
$token = $disk->getAdapter()->getUploadToken('folder/my_file.txt');
$token = $disk->getAdapter()->getUploadToken('folder/my_file.txt', 3600);

// get private url
$url = $disk->getAdapter()->privateDownloadUrl('folder/my_file.txt');

Full API documentation.

❤️ Sponsor me

Sponsor me

如果你喜欢我的项目并想支持它,点击这里 ❤️

Project supported by JetBrains

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?

请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》

License

MIT

laravel-filesystem-qiniu's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar hanson avatar hihuangwei avatar lex111 avatar overtrue avatar qbhy0715 avatar summerblue avatar yaoshanliang avatar zencodex 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  avatar  avatar  avatar

laravel-filesystem-qiniu's Issues

上传策略 fsizeLimit 在哪里配置或传入?

官方SDK示例如下,$policy中添加fsizeLimit等策略项:

//自定义返回值
$returnBody = '{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"name":"$(x:name)"}';
$policy = array(
    'returnBody' => $returnBody
);
$upToken = $auth->uploadToken($bucket, null, $expires, $policy, true);
print($upToken . "\n");

在本插件中如何使用呢?

请问下has方法中的疑惑

请问下has方法是指查看本地的路径还是在七牛云端的文件路径?
我使用has方法传入绝对路径,但是一直返回false文件也无法读取?

部分方法存在报错 Call to undefined method League\Flysystem\Filesystem::getAdapter()

以下方法存在报错

Call to undefined method League\Flysystem\Filesystem::getAdapter()

// fetch url content
$file = $disk->getAdapter()->fetch('folder/save_as.txt', $fromUrl);

// get file url
$url = $disk->getAdapter()->getUrl('folder/my_file.txt');

// get file upload token
$token = $disk->getAdapter()->getUploadToken('folder/my_file.txt');
$token = $disk->getAdapter()->getUploadToken('folder/my_file.txt', 3600);

// get private url
$url = $disk->getAdapter()->privateDownloadUrl('folder/my_file.txt');

升级qiniuSDK v7.2.0后报错,,回到v7.1.3好了

qq 20170823193240

php artisan backup:run

Starting backup...
Dumping database kuainiaoyaofei...
Determining files to backup...
Zipping 692 files...
Created zip containing 692 files. Size is 4.47 MB
Copying zip to disk named qiniu...
from query

Successfully copied zip to disk named qiniu.
Copying zip failed because: Undefined index: key.
Backup failed because Undefined index: key.
#0 /var/www/kuainiao/vendor/overtrue/flysystem-qiniu/src/QiniuAdapter.php(476): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined index...', '/var/www/kuaini...', 476, Array)

调用删除图片方法出现的问题

$disk = Storage::disk('qiniu');
$rs = $disk->delete($file_name);
使用上面的方法进行删除图片,调用后,返回true,再传相同的文件名,调用后返回false,说明方法没问题,但是去浏览器里访问这个图片的url,还是能访问到,没删除?

laravel5.4 listContents()返回为空

vendor/overtrue/flysystem-qiniu/src/QiniuAdapter.php
public function listContents()
return:

array (
0 =>
array (
'type' => 'file',
'path' => 'cover/2017/06/30/7D46QkBNnePJoswZQXqYseM08vJq9tsZXssT9DrX.jpg',
'timestamp' => 1498816002.0,
'size' => 51519,
),
1 =>
array (
'type' => 'file',
'path' => 'cover/2017/07/01/xUNgtbp2i5nWyhuSmM3EfIyuTd85hC4SqsSnVPH9.jpg',
'timestamp' => 1498880783.0,
'size' => 82849,
),
)

public function disk()
{
$disk = Storage::disk('qiniu');
$list = $disk->listContents();
dd($list);
}
[]

League\Flysystem\FileNotFoundException : File not found at path

use Storage;

...

$qiniuGlanceDisk = Storage::disk('qiniu');
$qiniuGlanceDisk->read('1.txt');
File not found at path: 1.txt {"exception":"[object] (League\\Flysystem\\FileNotFoundException(code: 0): File not found at path: 1.txt at vendor/league/flysystem/src/Filesystem.php:389)
[stacktrace]
#0 vendor/league/flysystem/src/Filesystem.php(179): League\\Flysystem\\Filesystem->assertPresent('1.txt')
#1 [internal function]: League\\Flysystem\\Filesystem->read('glance_upload/1...')
#2 vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php(729): call_user_func_array(Array, Array)
#3 app/Console/Commands/GlanceVideo.php(579): Illuminate\\Filesystem\\FilesystemAdapter->__call('read', Array)
#4 [internal function]: App\\Console\\Commands\\GlanceVideo->handle()
#5 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#6 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#7 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#8 vendor/laravel/framework/src/Illuminate/Container/Container.php(576): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#9 vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\\Container\\Container->call(Array)
#10 vendor/symfony/console/Command/Command.php(255): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#11 vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#12 vendor/symfony/console/Application.php(908): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#13 vendor/symfony/console/Application.php(269): Symfony\\Component\\Console\\Application->doRunCommand(Object(App\\Console\\Commands\\GlanceVideo), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#14 vendor/symfony/console/Application.php(145): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#15 vendor/laravel/framework/src/Illuminate/Console/Application.php(90): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#16 vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#17 artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#18 {main}
"} 
 League\Flysystem\FileNotFoundException  : File not found at path: 1.txt

  at vendor/league/flysystem/src/Filesystem.php:389
    385|      */
    386|     public function assertPresent($path)
    387|     {
    388|         if ($this->config->get('disable_asserts', false) === false && ! $this->has($path)) {
  > 389|             throw new FileNotFoundException($path);
    390|         }
    391|     }
    392|
    393|     /**

  Exception trace:

  1   League\Flysystem\Filesystem::assertPresent("1.txt")
      vendor/league/flysystem/src/Filesystem.php:179

  2   League\Flysystem\Filesystem::read("1.txt")
      vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php:729

在artisan自己的脚本里试了下,copy,move,read都不行,fetch,getUrl倒是可以的,请问是咋回事啊?config/filesystems.php已经加了七牛的配置了

laravel版本是5.8, "overtrue/laravel-filesystem-qiniu": "^1.0"

Trying to get property 'srcUpHosts' of non-object

Laravel version: 5.5
Package version: 1.0.1
Error Message: 'Trying to get property 'srcUpHosts' of non-object'
FIle path: 'qiniu/php-sdk/src/Qiniu/Config.php'

Code:

public function fetch($file, $prefix = null, $disk = null)
{
    $fileName = $this->getRandomFileName($file, $prefix);

    $storage = $this->getStorage($disk);

    $storage->put($fileName, fopen($file->getRealPath(), 'r'));

    return $storage->getUrl($fileName);
}

加密空间应该是属于配置类型的属性吧?

加密空间应该是属于配置类型的属性吧?
我在配置七牛文件驱动设置时,就应该确定该空间类型,是公开 还是私有;
如果是私有getUrl()应该默认获取加密文件链接。

fetch方法,文档的// fetch file $file = $disk->fetch('folder/my_file.txt');不成功

文档如下:

// fetch file 
$file = $disk->fetch('folder/my_file.txt');

源码中是接收两个参数?

namespace Overtrue\Flysystem\Qiniu\Plugins;

use League\Flysystem\Plugin\AbstractPlugin;

class FetchFile extends AbstractPlugin
{
    public function getMethod()
    {
        return 'fetch';
    }

    public function handle($path, $url)
    {
        return $this->filesystem->getAdapter()->fetch($path, $url);
    }
}

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.