A Qiniu Storage filesystem for Laravel

Overview

Laravel filesystem Qiniu

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

Requirement

  • PHP >= 5.5.9

Installation

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

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');
$time = $disk->getTimestamp('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->fetch('folder/save_as.txt', $fromUrl);

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

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

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

Full API documentation.

PHP 扩展包开发

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

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

License

MIT

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

    部分方法存在报错 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');
    
    opened by hihuangwei 5
  • 上传策略 fsizeLimit 在哪里配置或传入?

    上传策略 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");
    

    在本插件中如何使用呢?

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

    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);
        }
    }
    
    opened by never615 3
  • Trying to get property 'srcUpHosts' of non-object

    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);
    }
    
    opened by Seaony 2
  • 升级qiniuSDK v7.2.0后报错,,回到v7.1.3好了

    升级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)

    opened by numbersi 2
  •  Trying to get property 'srcUpHosts' of non-object

    Trying to get property 'srcUpHosts' of non-object

    error_reporting | Trying to get property 'srcUpHosts' of non-object -- | -- line | 48 code | 8 file | .../api/vendor/qiniu/php-sdk/src/Qiniu/Config.php

    opened by dahaigit 1
  • 调用删除图片方法出现的问题

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

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

    opened by jacky-zeng 1
  • laravel5.4 listContents()返回为空

    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); } []

    opened by bilwy 1
  • Upgrade to GitHub-native Dependabot

    Upgrade to GitHub-native Dependabot

    Dependabot Preview will be shut down on August 3rd, 2021. In order to keep getting Dependabot updates, please merge this PR and migrate to GitHub-native Dependabot before then.

    Dependabot has been fully integrated into GitHub, so you no longer have to install and manage a separate app. This pull request migrates your configuration from Dependabot.com to a config file, using the new syntax. When merged, we'll swap out dependabot-preview (me) for a new dependabot app, and you'll be all set!

    With this change, you'll now use the Dependabot page in GitHub, rather than the Dependabot dashboard, to monitor your version updates, and you'll configure Dependabot through the new config file rather than a UI.

    If you've got any questions or feedback for us, please let us know by creating an issue in the dependabot/dependabot-core repository.

    Learn more about migrating to GitHub-native Dependabot

    Please note that regular @dependabot commands do not work on this pull request.

    dependencies 
    opened by dependabot-preview[bot] 0
  • League\Flysystem\FileNotFoundException  : File not found at path

    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"

    opened by forgottener 0
Releases(2.1.0)
Owner
安正超
Keep calm and coding.
安正超
Shell Tools for Qiniu Cloud

qshell 简介 qshell是利用七牛文档上公开的API实现的一个方便开发者测试和使用七牛API服务的命令行工具。该工具设计和开发的主要目的就是帮助开发者快速解决问题。目前该工具融合了七牛存储,CDN,以及其他的一些七牛服务中经常使用到的方法对应的便捷命令,比如b64decode,就是用来解码七

Qiniu Cloud 956 Dec 26, 2022
Laravel illuminate/filesystem for webman

webman-tech/laravel-filesystem Laravel illuminate/filesystem for webman 介绍 站在巨人(laravel)的肩膀上使文件存储使用更加可靠和便捷 所有方法和配置与 laravel 几乎一模一样,因此使用方式完全参考 Laravel文

null 5 Dec 15, 2022
Egnyte Filesystem

Egnyte Filesystem I was working on Egnyte project for Laravel and didn't find any decent solution so decided to write my own. Inspired by Yespbs\Egnyt

null 2 Apr 27, 2022
Mage2click toolset to create and manage the Magento Docker development environment with mutagen.io file-sync for macOS and native filesystem mounts on Linux.

Mage2click - Magento Docker Toolset Mage2click toolset is a system-wide command-line tool for creating and managing simultaneously running Magento Doc

Mage2click 69 Nov 28, 2022
Laravel & Google Drive Storage - Demo project with Laravel 6.x and earlier

Laravel & Google Drive Storage Demo project with Laravel 8.X Look at the commit history to see each of the steps I have taken to set this up. Set up t

null 23 Oct 3, 2022
A simple mailable trait and interface to export mails to a storage disk once being sent.

Laravel Mail Export This package can export any mail sent with Laravel's Mailable class to any desired filesystem disk and path as a .eml file. This c

Pod Point 80 Nov 6, 2022
Greyhole uses Samba to create a storage pool of all your available hard drives, and allows you to create redundant copies of the files you store.

Greyhole Greyhole is an application that uses Samba to create a storage pool of all your available hard drives (whatever their size, however they're c

Guillaume Boudreau 245 Dec 18, 2022
Upload attachments to content storage platform like Aliyun OSS, Tencent COS

Overview Yun storage provides a layer that mediates between a user or configured storage frontend and one or several storage backends. Note: jichangfe

Changfeng Ji 2 Oct 13, 2021
High-performance, low-memory-footprint, single-file embedded database for key/value storage

LDBA - a fast, pure PHP, key-value database. Information LDBA is a high-performance, low-memory-footprint, single-file embedded database for key/value

Simplito 12 Nov 13, 2022
This Repo is a storage of Postman collections for Magento

Magento Postman repository This Repository is a storage of Postman collections for Magento. If you have what to share, you are welcome to contribute a

Lyzun Oleksandr 14 May 17, 2022
File uploads with validation and storage strategies

Upload This component simplifies file validation and uploading. Usage Assume a file is uploaded with this HTML form: <form method="POST" enctype="mult

Brandon Savage 1.7k Dec 27, 2022
Google Cloud Storage for PHP

Google Cloud Storage for PHP Idiomatic PHP client for Cloud Storage. API documentation NOTE: This repository is part of Google Cloud PHP. Any support

Google APIs 281 Nov 10, 2022
File Storage Api

flux-file-storage-api File Storage Api Installation Native Download RUN (mkdir -p /%path%/libs/flux-file-storage-api && cd /%path%/libs/flux-file-stor

null 1 Dec 12, 2022
Microsoft Azure Storage Library for PHP

Microsoft Azure Storage PHP Client Libraries This project will be in Community Support and Azure Storage team commits to validate and release every qu

Microsoft Azure 201 Nov 30, 2022
Laravel Blog Package. Easiest way to add a blog to your Laravel website. A package which adds wordpress functionality to your website and is compatible with laravel 8.

Laravel Blog Have you worked with Wordpress? Developers call this package wordpress-like laravel blog. Give our package a Star to support us ⭐ ?? Inst

Binshops 279 Dec 28, 2022
A Simple Linode SDK built for Laravel with @JustSteveKing laravel-transporter package

linode client A Simple Linode client built for Laravel with @JustSteveKing laravel-transporter package Installation You can install the package via co

Samuel Mwangi 2 Dec 14, 2022
A Laravel Wrapper for the Binance API. Now easily connect and consume the Binance Public & Private API in your Laravel apps without any hassle.

This package provides a Laravel Wrapper for the Binance API and allows you to easily communicate with it. Important Note This package is in early deve

Moinuddin S. Khaja 7 Dec 7, 2022
Laravel Podcast Manager is a complete podcast manager package for Laravel 5.3+ that enables you to manage RSS feeds for your favorite podcasts and listen to the episodes in a seamless UI.

laravelpodcast | A Laravel podcast manager package - v0.0.8 Introduction Laravel Podcast Manager is a complete podcast manager package for Laravel 5.3

Jeremy Kenedy 22 Nov 4, 2022
Laravel-htaccess - a package for dynamically edit .htaccess in laravel

laravel-htaccess a package for dynamically edit .htaccess in laravel use RedirectHtaccess Facade function for add RedirectHtaccess()->add(); return in

Mohammad khazaee 3 Dec 19, 2021