Aliyun oss filesystem storage adapter for laravel 5. You can use Aliyun OSS just like laravel Storage as usual

Overview

Aliyun-oss-storage for Laravel 5+

Aliyun oss filesystem storage adapter for laravel 5. You can use Aliyun OSS just like laravel Storage as usual.
借鉴了一些优秀的代码,综合各方,同时做了更多优化,将会添加更多完善的接口和插件,打造Laravel最好的OSS Storage扩展

Inspired By

Require

  • Laravel 5+
  • cURL extension

##Installation In order to install AliOSS-storage, just add

"jacobcyl/ali-oss-storage": "^2.1"

to your composer.json. Then run composer install or composer update.
Or you can simply run below command to install:

"composer require jacobcyl/ali-oss-storage:^2.1"

Then in your config/app.php add this line to providers array:

Jacobcyl\AliOSS\AliOssServiceProvider::class,

Configuration

Add the following in app/filesystems.php:

'disks'=>[
    ...
    'oss' => [
            'driver'        => 'oss',
            'access_id'     => '
   
    '
   ,
            'access_key'    => '
   
    '
   ,
            'bucket'        => '
   
    '
   ,
            'endpoint'      => '
   
    '
   , // OSS 外网节点或自定义外部域名
            //'endpoint_internal' => '
   
    ', // v2.0.4 新增配置属性,如果为空,则默认使用 endpoint 配置(由于内网上传有点小问题未解决,请大家暂时不要使用内网节点上传,正在与阿里技术沟通中)
   
            'cdnDomain'     => '
   
    '
   , // 如果isCName为true, getUrl会判断cdnDomain是否设定来决定返回的url,如果cdnDomain未设置,则使用endpoint来生成url,否则使用cdn
            'ssl'           => <true|false> // true to use 'https://' and false to use 'http://'. default is false,
            'isCName'       => <true|false> // 是否使用自定义域名,true: 则Storage.url()会使用自定义的cdn或域名生成文件url, false: 则使用外部节点生成url
            'debug'         => <true|false>
    ],
    ...
]

Then set the default driver in app/filesystems.php:

'default' => 'oss',

Ok, well! You are finish to configure. Just feel free to use Aliyun OSS like Storage!

Usage

See Larave doc for Storage Or you can learn here:

First you must use Storage facade

use Illuminate\Support\Facades\Storage;

Then You can use all APIs of laravel Storage

Storage::disk('oss'); // if default filesystems driver is oss, you can skip this step

//fetch all files of specified bucket(see upond configuration)
Storage::files($directory);
Storage::allFiles($directory);

Storage::put('path/to/file/file.jpg', $contents); //first parameter is the target file path, second paramter is file content
Storage::putFile('path/to/file/file.jpg', 'local/path/to/local_file.jpg'); // upload file from local path

Storage::get('path/to/file/file.jpg'); // get the file object by path
Storage::exists('path/to/file/file.jpg'); // determine if a given file exists on the storage(OSS)
Storage::size('path/to/file/file.jpg'); // get the file size (Byte)
Storage::lastModified('path/to/file/file.jpg'); // get date of last modification

Storage::directories($directory); // Get all of the directories within a given directory
Storage::allDirectories($directory); // Get all (recursive) of the directories within a given directory

Storage::copy('old/file1.jpg', 'new/file1.jpg');
Storage::move('old/file1.jpg', 'new/file1.jpg');
Storage::rename('path/to/file1.jpg', 'path/to/file2.jpg');

Storage::prepend('file.log', 'Prepended Text'); // Prepend to a file.
Storage::append('file.log', 'Appended Text'); // Append to a file.

Storage::delete('file.jpg');
Storage::delete(['file1.jpg', 'file2.jpg']);

Storage::makeDirectory($directory); // Create a directory.
Storage::deleteDirectory($directory); // Recursively delete a directory.It will delete all files within a given directory, SO Use with caution please.

// upgrade logs
// new plugin for v2.0 version
Storage::putRemoteFile('target/path/to/file/jacob.jpg', 'http://example.com/jacob.jpg'); //upload remote file to storage by remote url
// new function for v2.0.1 version
Storage::url('path/to/img.jpg') // get the file url

Documentation

More development detail see Aliyun OSS DOC

License

Source code is release under MIT license. Read LICENSE file for more information.

Comments
  • 建议添加内网Endpoint上传功能

    建议添加内网Endpoint上传功能

    建议添加ECS访问的内网Endpoint,如果设置内网Endpoint,则由内网Endpoint(oss-cn-hangzhou-internal.aliyuncs.com)上传,外网Endpoint(oss-cn-hangzhou.aliyuncs.com)下载。如果未添加内网Endpoint,全部由外网Endpoint上传、下载。

    help wanted 
    opened by holox 4
  • ReadStream wrap to stream if string returned

    ReadStream wrap to stream if string returned

    This pull request intoduces solution like this PR https://github.com/jacobcyl/Aliyun-oss-storage/pull/50 but with another implemented code. Problem if $result['raw_contents'] contains string instead of resource

    opened by dmitryuk 2
  • 支持laravel5.3吗

    支持laravel5.3吗

    在laravel5.3中使用时putFile方法时会报错。 下面是5.3中FilesystemAdapter.php中putFile方法 public function putFile($path, $file, $visibility = null) { return $this->putFileAs($path, $file, $file->hashName(), $visibility); } 其中第二个参数是UploadedFile类型,而文档中写的是传string类型

    opened by qinghua0706 2
  • 建议不要捕获错误

    建议不要捕获错误

    在大多数能引发OssException的地方,都被Catch,然后简单的return false了。 但是这样在项目运行时,可能会引发一些潜在问题。

    另外:在listContents方法中,调用了listDirObjects,但是当listDirObjects发生错误时,没有做异常判定。导致异常抛出。

    不捕获OssException是不是更好一些?

    opened by harde 2
  • ssl的配置无效(从request取也不合理)

    ssl的配置无效(从request取也不合理)

    在配置项中,有 ssl = true/false 的配置 但是在实际代码中(AliOssServiceProvider:42),是从$app['request']->secure()获取的。

    这在正式环境是理论上是没有问题的。 但是在开发环境下,可能会出现问题,因为CDN设置很可能只接受https请求。 但是开发环境往往又只是http请求。

    opened by harde 1
  • cURL error

    cURL error

    OssException In OssClient.php line 1994 :
    
    RequestCoreException: cURL resource: Resource id #350; cURL error: Connection timed out after 10073 milliseconds (28)
    
    opened by xus898 1
  • Storage::url报错:object name is empty

    Storage::url报错:object name is empty

    调用: Storage::url($user->headimg) 问题: object name is empty {"exception":"[object] (OSS\Core\OssException(code: 0): object name is empty at /www/wwwroot/xxx.xx.xx/vendor/aliyuncs/oss-sdk-php/src/OSS/Core/OssUtil.php:225)

    opened by ygcool 0
  • Resolving timed out

    Resolving timed out

    Previously was fine but today when I'm tried to upload / delete, I receive this type of error:

    OSS\Core\OssException: RequestCoreException: cURL resource: Resource id #393; cURL error: Resolving timed out after 10531 milliseconds (28) in /var/www/monsterpress/vendor/aliyuncs/oss-sdk-php/src/OSS/OssClient.php:2187

    opened by momokang 0
  • Required parameter $cdnDomain follows optional parameter $isCname

    Required parameter $cdnDomain follows optional parameter $isCname

    使用php 8.0會出現:Required parameter $cdnDomain follows optional parameter $isCname 問題在 jacobcyl/ali-oss-storage/src/AliOssAdapter.php 的 __construct function 的 signature 不是required的 $isCname 放於required的 $cdnDomain

    opened by kalokcheung 2
  • 资源找不到,在非调试模式下,应该返回空或null,而不是异常

    资源找不到,在非调试模式下,应该返回空或null,而不是异常

    Aliyun-oss-storage/src/AliOssAdapter.php 为什么在这里获取url,不存在时直接就异常!

    /** * @param $path * * @return string */ public function getUrl( $path ) { if (!$this->has($path)) throw new FileNotFoundException($filePath.' not found'); return ( $this->ssl ? 'https://' : 'http://' ) . ( $this->isCname ? ( $this->cdnDomain == '' ? $this->endPoint : $this->cdnDomain ) : $this->bucket . '.' . $this->endPoint ) . '/' . ltrim($path, '/'); }

    路径无法找到,仅仅是资源不存在而已,并不是程序无法进行下去,返回空或者null都可以,这里返回异常导致整个程序奔溃。 这里没有结合laravel的环境,调试模式下异常抛出会不会更好,

    opened by jorry2008 0
  • 图片不存在会报异常类不存在

    图片不存在会报异常类不存在

    Class 'Symfony\Component\Filesystem\Exception\FileNotFoundException' not found 在laravel8.x中 public function getUrl( $path ) { if (!$this->has($path)) throw new FileNotFoundException($filePath.' not found'); return ( $this->ssl ? 'https://' : 'http://' ) . ( $this->isCname ? ( $this->cdnDomain == '' ? $this->endPoint : $this->cdnDomain ) : $this->bucket . '.' . $this->endPoint ) . '/' . ltrim($path, '/'); }

    opened by LearvSmith 0
Releases(2.1.0)
Owner
jacob
A Geeker,An Artist,A Genius. Above all are not me, But close 💯 A artistic programer ,I think I am!
jacob
Google Cloud Storage filesystem driver for Laravel

Google Cloud Storage filesystem driver for Laravel Google Cloud Storage filesystem driver for Laravel. This started as a fork from Superbalist/laravel

Spatie 88 Dec 16, 2022
A filesystem-like repository for storing arbitrary resources.

The Puli Repository Component Latest release: 1.0.0-beta10 PHP >= 5.3.9 The Puli Repository Component provides an API for storing arbitrary resources

Puli 435 Nov 20, 2022
This package can use form request just as Laravel do.

Lumen Form Request This package can use form request just as Laravel do. Installation Install by composer $ composer require chhw/form-request In

null 2 Nov 17, 2021
A package that adds view-composer like feature to Inertia.js Laravel adapter

Kinetic A package that adds view-composer like feature to Inertia.js Laravel adapter. Use to be able to share props based on the Inertia component nam

Marvin Quezon 76 Dec 12, 2022
A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly.

PHPColors A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly. Requirements PHPColo

Arlo Carreon 423 Dec 20, 2022
Flysystem storage with local metadata storage for speed and manageability.

Laravel Filer This project was started to scratch my itch on our growing Laravel site: Metadata for all files is stored in a local repository - Suppor

Nick Vahalik 16 May 23, 2022
Laravel Package - Files to S3 Like Cloud Storage

This is a Laravel package that handles and make easy the upload, overwrite, delete, cdn purge of files and directories on AWS S3 like cloud storages. It supports a form uploaded file (UploadedFile) or a base64 file string

André G. Inocenti Lobo Viana 3 Jun 17, 2022
⚡ Laravel Charts — Build charts using laravel. The laravel adapter for Chartisan.

What is laravel charts? Charts is a Laravel library used to create Charts using Chartisan. Chartisan does already have a PHP adapter. However, this li

Erik C. Forés 31 Dec 18, 2022
If you are beginner in WordPress plugin development or if you want to develop your own store product plugin you use this plugin

hirwa-products-plugin If you are beginner in WordPress plugin development or if you want to develop your own store product plugin you use this plugin

NIYIBIZI HIRWA 1 Aug 23, 2022
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.

Laravel Befriended Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked

Renoki Co. 720 Jan 3, 2023
A Laravel chat package. You can use this package to create a chat/messaging Laravel application.

Chat Create a Chat application for your multiple Models Table of Contents Click to expand Introduction Installation Usage Adding the ability to partic

Tinashe Musonza 931 Dec 24, 2022
Collection of classes you can use to standardize data formats in your Laravel application.

Laravel Formatters This package is a collection of classes you can use to standardize data formats in your Laravel application. It uses the Service Co

Michael Rubel 88 Dec 23, 2022
you can use this package with your develop operation....

Laravel Debugbar This is a package to integrate PHP Debug Bar with Laravel. It includes a ServiceProvider to register the debugbar and attach it to th

Eng Hasan Hajjar 2 Sep 30, 2022
A simple blog app where a user can signup , login, like a post , delete a post , edit a post. The app is built using laravel , tailwind css and postgres

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Nahom_zd 1 Mar 6, 2022
Make custom helper just with one command!

Laravel Custom Helper Make custom helper just with one command! Very light!!! Installation requires Laravel 8+ Via composer: $ composer require Ranjba

Ali Ranjbar 2 Aug 23, 2022
A Laravel package that allows you to use multiple ".env" files in a precedent manner. Use ".env" files per domain (multi-tentant)!

Laravel Multi ENVs Use multiple .envs files and have a chain of precedence for the environment variables in these different .envs files. Use the .env

Allyson Silva 48 Dec 29, 2022
A simple Content Moderation System for Laravel 5.* that allows you to Approve or Reject resources like posts, comments, users, etc.

Laravel Moderation A simple Moderation System for Laravel 5.* that allows you to Approve or Reject resources like posts, comments, users, etc. Keep yo

Alex Kyriakidis 509 Dec 30, 2022
cybercog 996 Dec 28, 2022
This package allows you to render livewire components like a blade component, giving it attributes, slots etc

X-livewire This package allows you to render livewire components like a blade component, giving it attributes, slots etc. Assuming you wanted to creat

null 7 Nov 15, 2022