PHPackages                             mitoop/laravel-alioss-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. mitoop/laravel-alioss-storage

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

mitoop/laravel-alioss-storage
=============================

Aliyun OSS storage in laravel.

v2.0.2(1y ago)83.2k1MITPHP

Since Oct 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mitoop/laravel-alioss-storage)[ Packagist](https://packagist.org/packages/mitoop/laravel-alioss-storage)[ RSS](/packages/mitoop-laravel-alioss-storage/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (8)Used By (0)

Laravel Aliyun OSS Filesystem Storage
=====================================

[](#laravel-aliyun-oss-filesystem-storage)

Install
-------

[](#install)

> composer require mitoop/laravel-alioss-storage

Laravel 版本低于5.5版本 请添加`Mitoop\AliOSS\ServiceProvider` 到 `config/app.php` 的 `providers` 数组

Laravel 9 起 依赖 `league/flysystem` 版本发生变化, 接口约束也发生了变化

Require
-------

[](#require)

- > Laravel 5+ &amp;&amp; &lt; Laravel 9

Configure
---------

[](#configure)

在 `config/filesystems.php` 的 `disk`里增加配置:

```
 'oss' => [ // 定义的disk名称, 自定义，只要不重复就行
    'driver'            => 'oss', // 使用的驱动，这里只能填写 `oss` [必填]
    'access_key_id'     => env('OSS_ACCESS_ID', 'access_key_id'), // OSS access_key_id [必填]
    'access_key_secret' => env('OSS_ACCESS_KEY', 'access_key_secret'), // OSS access_key_secret [必填]
    'endpoint'          => env('OSS_ENDPOINT', 'endpoint'), // OSS endpoint [必填]
    'bucket'            => env('OSS_BUCKET', 'bucket'), // OSS bucket [必填]
    'custom_domain'     => 'http://foo.bar', // 自定义域名， 参考下方说明
    'schema'            => env('OSS_SCHEMA', 'https'), // 使用默认域名时用的 url schema, 参考下方说明
    'plugins'           => [], // 可以自己封装插件，实现更多方法 参考下方说明
 ],

  说明:
  1. 自定义域名
  获取 OSS URL 的时候，默认地址是 bucket.endpoint/path，指定 schema 后为 http(s)://bucket.endpoint/path
  当使用自定义域名后, 就不再使用默认地址，schema 此时就不起作用了, 获取地址变为：自定义域名/path

  2. 插件
  如果要实现更多方法，在 `plugins` 里添加上对应类， 例如
  'plugins' => [
      DoSomethingPlugin::class,
  ],
  插件类应该继承 `\Mitoop\AliOSS\PluginsAbstractPlugin`
  或者继承 `League\Flysystem\Plugin\AbstractPlugin`

```

Use
---

[](#use)

可以使用 Laravel Storage 的所有方法

集成插件提供的方法 :

- signUrl ```
    使用签名URL进行临时授权(主要对私有对象使用).

    Storage::disk('oss')->signUrl($path, $timeout);

    ```
- putRemoteFile ```
    将本地文件或者远程URL文件存储到oss.

    Storage::disk('oss')->putRemoteFile($path, $remoteUrl);

    ```

Notice
------

[](#notice)

1. `deleteDir` 删除文件夹方法. 方法直接返回为 false, 不会进行删除，如果要删除文件夹强烈推荐到阿里云后台操作.
2. `listContents` 列出文件夹目录(支持递归)方法. 方法直接返回为空数组 \[\], 如果有此业务，可以考虑通过插件实现.
3. 除了 `has` 方法, 所有方法在失败的时候都会返回 false (不抛出异常，但有日志记录),

    如果需要, 你可以用 === false 来判断是否成功. 配置正常的情况下, 失败概率极低.
4. `has` 方法, 本身返回 true / false, 所以发生错误会抛出异常.
5. `$request->file('avatar')->store('avatars');` 上传文件直接 `store` 就生成随机名称，这里的 `avatars` 只是目录名称

    所以推荐使用 `storeAs` 方法来达到预期的目的.

    曾经遇到过 `store` 方法生成随机名称获取扩展的时候，对于 WPS 的 docx/pptx, 总是获取不到正确的文件扩展名称

    最后 `storeAs` 手动解决了.
6. `temporaryUrl` 方法和 `signUrl` 是一样的效果, 区别仅在于第二个参数

    `signUrl` 传入的 int 类型, 例如, 传入30表示30秒后过期

    `temporaryUrl` 传入的是 `\DateTimeInterface` 类型, 例如, 传入 now()-&gt;addSeconds(30) 也是表示30秒后过期

More
----

[](#more)

Storage方法通常会提供 `options` 参数. 最常用的就是设置文件可见性.

设置可见性：

```
// 只设置可见行，直接 public
Storage::disk('oss')->put('file.jpg', $contents, 'public');
或
// 还有其他 option 配置时使用 ['visibility' => 'private']
Storage::disk('oss')->put('file.jpg', $contents, ['visibility' => 'private'])

public 对应 OSS 的公开读权限
private 对应 OSS 的私有权限
不单独设置可见性, 默认继承 bucket 的可见性

```

Links
-----

[](#links)

[https://help.aliyun.com/document\_detail/32099.html](https://help.aliyun.com/document_detail/32099.html)

License
-------

[](#license)

```
        DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                    Version 2, December 2004

 Copyright (C) 2004 Sam Hocevar

 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as long
 as the name is changed.

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. You just DO WHAT THE FUCK YOU WANT TO.

```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance40

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~376 days

Recently: every ~549 days

Total

7

Last Release

505d ago

Major Versions

v0.0.1 → v1.0.02018-10-19

v1.1.2 → v2.0.12020-05-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/1645a978f51dcbbc8e50a17bf7daaa12fd1b01a4b19784d0010325d78c9b53f8?d=identicon)[Mitoop](/maintainers/Mitoop)

---

Top Contributors

[![mitoop](https://avatars.githubusercontent.com/u/7368344?v=4)](https://github.com/mitoop "mitoop (7 commits)")

---

Tags

aliosslaravel-alioss-storage

### Embed Badge

![Health badge](/badges/mitoop-laravel-alioss-storage/health.svg)

```
[![Health](https://phpackages.com/badges/mitoop-laravel-alioss-storage/health.svg)](https://phpackages.com/packages/mitoop-laravel-alioss-storage)
```

###  Alternatives

[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.6k263.6M790](/packages/league-flysystem-aws-s3-v3)[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.3M74](/packages/unisharp-laravel-filemanager)[league/flysystem-sftp-v3

SFTP filesystem adapter for Flysystem.

6129.6M91](/packages/league-flysystem-sftp-v3)[iidestiny/flysystem-oss

Flysystem adapter for the Oss storage.

95607.5k26](/packages/iidestiny-flysystem-oss)[yii2-starter-kit/yii2-file-kit

Yii2 file upload and storage kit

151216.8k6](/packages/yii2-starter-kit-yii2-file-kit)[xxtime/flysystem-aliyun-oss

AliYun OSS adapter for flysystem. Support PHP8. aliyuncs/oss-sdk-php ~2.6

51505.3k28](/packages/xxtime-flysystem-aliyun-oss)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
