PHPackages                             jichangfeng/laravel-yun-storage - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. jichangfeng/laravel-yun-storage

ActiveLibrary[File &amp; Storage](/categories/file-storage)

jichangfeng/laravel-yun-storage
===============================

Upload attachments to content storage platform like Aliyun OSS, Tencent COS

v1.8(2y ago)1761MITPHPPHP &gt;=5.6

Since Sep 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/jichangfeng/laravel-yun-storage)[ Packagist](https://packagist.org/packages/jichangfeng/laravel-yun-storage)[ Docs](http://github.com/jichangfeng/laravel-yun-storage)[ RSS](/packages/jichangfeng-laravel-yun-storage/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (9)Dependencies (1)Versions (10)Used By (0)

Overview
========

[](#overview)

[![Latest Stable Version](https://camo.githubusercontent.com/840ca7ef982f0cc166c9299b21e8373d0308fe7b6ccba22ac582b8d9019d0e49/68747470733a2f2f706f7365722e707567782e6f72672f6a696368616e6766656e672f6c61726176656c2d79756e2d73746f726167652f762f737461626c652e706e67)](https://packagist.org/packages/jichangfeng/laravel-yun-storage)[![Total Downloads](https://camo.githubusercontent.com/8e88c7937f9568c8009b307aed6e93ef5a5f17fb8d1bc81aee18cdacc924372f/68747470733a2f2f706f7365722e707567782e6f72672f6a696368616e6766656e672f6c61726176656c2d79756e2d73746f726167652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/jichangfeng/laravel-yun-storage)[![License](https://camo.githubusercontent.com/cda198ce6a9b2f10a656ba5664949f262d4d793bbdda7df5700e3a1983fdadcc/68747470733a2f2f706f7365722e707567782e6f72672f6a696368616e6766656e672f6c61726176656c2d79756e2d73746f726167652f6c6963656e73652e706e67)](https://packagist.org/packages/jichangfeng/laravel-yun-storage)

Laravel yun storage is a simple, but elegant laravel wrapper around [jichangfeng/yun-storage](https://github.com/jichangfeng/yun-storage).

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

Supported back-end storage
==========================

[](#supported-back-end-storage)

- [Aliyun OSS](https://www.aliyun.com/product/oss)
- [Tencent COS](https://cloud.tencent.com/product/cos)

Run environment
===============

[](#run-environment)

- PHP 5.6+

Install
=======

[](#install)

### Composer

[](#composer)

Execute the following command to get the latest version of the package:

```
composer require jichangfeng/laravel-yun-storage

```

### Laravel &gt;= 5.5

[](#laravel--55)

- ServiceProvider、Facades will be attached automatically

#### Laravel &lt; 5.5

[](#laravel--55-1)

In your `config/app.php` add `YunStorage\Laravel\YunStorageServiceProvider::class` to the end of the `providers` array:

```
'providers' => [
    ...
    YunStorage\Laravel\YunStorageServiceProvider::class,
],
```

In your `config/app.php` add `YunStorageFacade` to the end of the `aliases` array:

```
'aliases' => [
    ...
    'YunStorageFacade' => YunStorage\Laravel\YunStorageFacade::class,
],
```

#### Publish Configuration

[](#publish-configuration)

```
php artisan vendor:publish --provider "YunStorage\Laravel\YunStorageServiceProvider"
```

Usage
=====

[](#usage)

#### Configuration

[](#configuration)

```
return [
    /*
      |--------------------------------------------------------------------------
      | Default Storage Adapter
      |--------------------------------------------------------------------------
      |
      | This option controls the default storage adapter that gets used while
      | using this yun storage library.
      |
      | Supported: "oss", "cos"
      |
     */
    'default' => env('YUN_STORAGE_ADAPTER', ''),
    /*
      |--------------------------------------------------------------------------
      | Storage Adapters
      |--------------------------------------------------------------------------
      |
      | Here you may define all of the storage "adapters" for your application as
      | well as their storage adapters.
      |
     */
    'adapters' => [
        'oss' => [
            'accessKeyId' => env('YUN_STORAGE_OSS_ACCESS_KEY_ID', ''),
            'accessKeySecret' => env('YUN_STORAGE_OSS_ACCESS_KEY_SECRET', ''),
            'endpoint' => env('YUN_STORAGE_OSS_ENDPOINT', ''),
        ],
        'cos' => [
            'accessKeyId' => env('YUN_STORAGE_COS_ACCESS_KEY_ID', ''),
            'accessKeySecret' => env('YUN_STORAGE_COS_ACCESS_KEY_SECRET', ''),
            'region' => env('YUN_STORAGE_COS_REGION', ''),
            'schema' => env('YUN_STORAGE_COS_SCHEMA', 'http'),
            'appid' => env('YUN_STORAGE_COS_APPID', ''),
        ]
    ]
];
```

#### Instruction

[](#instruction)

```
try {
    //Set the default storage adapter name. Supported: "oss", "cos"
    \YunStorage\Laravel\YunStorageFacade::setDefaultAdapter('oss');
    //
    //If your application interacts with default storage adapter.
    \YunStorage\Laravel\YunStorageFacade::putObject($bucket, $object, $content);
    //
    //If your application interacts with multiple storage adapters,
    //you may use the 'adapter' method to work on a particular storage adapter.
    \YunStorage\Laravel\YunStorageFacade::adapter('oss')->putObject($bucket, $object, $content);
    \YunStorage\Laravel\YunStorageFacade::adapter('cos')->putObject($bucket, $object, $content);
    //
    //Directly call the storage object at the back-end of the storage adapter
    \YunStorage\Laravel\YunStorageFacade::adapter()->client();
    \YunStorage\Laravel\YunStorageFacade::adapter('oss')->client()->listObjects($bucket, $options);
    \YunStorage\Laravel\YunStorageFacade::adapter('cos')->client()->listObjects($arg);
} catch (\Exception $e) {
    echo $e->getMessage();
}
```

#### Method

[](#method)

```
try {
    //Creates bucket
    \YunStorage\Laravel\YunStorageFacade::createBucket($bucket);
    //
    //Checks if a bucket exists
    \YunStorage\Laravel\YunStorageFacade::doesBucketExist($bucket);
    //
    //Deletes bucket
    \YunStorage\Laravel\YunStorageFacade::deleteBucket($bucket);
    //
    //Lists the Bucket
    \YunStorage\Laravel\YunStorageFacade::listBuckets();
    //
    //Uploads the $content object.
    \YunStorage\Laravel\YunStorageFacade::putObject($bucket, $object, $content);
    //
    //Checks if the object exists
    \YunStorage\Laravel\YunStorageFacade::doesObjectExist($bucket, $object);
    //
    //Deletes a object
    \YunStorage\Laravel\YunStorageFacade::deleteObject($bucket, $object);
    //
    //Deletes multiple objects in a bucket
    \YunStorage\Laravel\YunStorageFacade::deleteObjects($bucket, $objects);
    //
    //Gets Object content
    \YunStorage\Laravel\YunStorageFacade::getObject($bucket, $object);
    //
    //Lists the bucket's object keys
    \YunStorage\Laravel\YunStorageFacade::listObjectKeys($bucket, $prefix);
    //
    //Uploads a local file
    \YunStorage\Laravel\YunStorageFacade::uploadFile($bucket, $object, $localfile);
    //
    //Downloads to local file
    \YunStorage\Laravel\YunStorageFacade::downloadFile($bucket, $object, $localfile);
    //
    // Gets the storage client, return the actual storage object
    \YunStorage\Laravel\YunStorageFacade::adapter()->client();
} catch (\Exception $e) {
    echo $e->getMessage();
}
```

#### Example

[](#example)

```
