{"id":23899279,"url":"https://github.com/alphasnow/aliyun-oss-laravel","last_synced_at":"2025-04-04T15:09:15.168Z","repository":{"id":37324076,"uuid":"341799495","full_name":"alphasnow/aliyun-oss-laravel","owner":"alphasnow","description":"Alibaba Cloud Object Storage Service For Laravel. 阿里云对象存储服务扩展包, 支持最新版的Laravel. ","archived":false,"fork":false,"pushed_at":"2024-06-14T01:48:48.000Z","size":219,"stargazers_count":164,"open_issues_count":0,"forks_count":17,"subscribers_count":1,"default_branch":"4.x","last_synced_at":"2025-03-28T14:07:02.972Z","etag":null,"topics":["aliyun","filesystem","flysystem-adapter","laravel","laravel-filesystem","laravel-package","oss","php","storage"],"latest_commit_sha":null,"homepage":"https://alphasnow.github.io/aliyun-oss-laravel/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alphasnow.png","metadata":{"files":{"readme":"README-CN.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-24T06:17:06.000Z","updated_at":"2025-03-27T06:47:05.000Z","dependencies_parsed_at":"2023-01-22T20:45:35.617Z","dependency_job_id":"26286e06-2781-4f65-b912-ca22eeea10d7","html_url":"https://github.com/alphasnow/aliyun-oss-laravel","commit_stats":{"total_commits":172,"total_committers":5,"mean_commits":34.4,"dds":0.03488372093023251,"last_synced_commit":"143a11ef4b881ede82cc7f7abcb7cd87152c2891"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphasnow%2Faliyun-oss-laravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphasnow%2Faliyun-oss-laravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphasnow%2Faliyun-oss-laravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphasnow%2Faliyun-oss-laravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alphasnow","download_url":"https://codeload.github.com/alphasnow/aliyun-oss-laravel/tar.gz/refs/heads/4.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198461,"owners_count":20900080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aliyun","filesystem","flysystem-adapter","laravel","laravel-filesystem","laravel-package","oss","php","storage"],"created_at":"2025-01-04T18:17:13.692Z","updated_at":"2025-04-04T15:09:15.147Z","avatar_url":"https://github.com/alphasnow.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[English](README.md) | 简体中文  \n\n# Aliyun OSS Laravel\n\n[![Latest Stable Version](https://poser.pugx.org/alphasnow/aliyun-oss-laravel/v/stable)](https://packagist.org/packages/alphasnow/aliyun-oss-laravel)\n[![Total Downloads](https://poser.pugx.org/alphasnow/aliyun-oss-laravel/downloads)](https://packagist.org/packages/alphasnow/aliyun-oss-laravel)\n[![tests](https://github.com/alphasnow/aliyun-oss-laravel/actions/workflows/tests.yml/badge.svg?branch=4.x)](https://github.com/alphasnow/aliyun-oss-laravel/actions/workflows/tests.yml)\n[![License](https://poser.pugx.org/alphasnow/aliyun-oss-laravel/license)](https://packagist.org/packages/alphasnow/aliyun-oss-laravel)\n[![Coverage Status](https://coveralls.io/repos/github/alphasnow/aliyun-oss-laravel/badge.svg?branch=4)](https://coveralls.io/github/alphasnow/aliyun-oss-laravel?branch=4)\n\n[![Banner](https://banners.beyondco.de/Aliyun%20OSS%20Laravel.png?theme=light\u0026packageManager=composer+require\u0026packageName=alphasnow%2Faliyun-oss-laravel\u0026pattern=architect\u0026style=style_1\u0026description=Alibaba+Cloud+Object+Storage+Service+For+Laravel\u0026md=1\u0026showWatermark=1\u0026fontSize=100px\u0026images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg)](https://github.com/alphasnow/aliyun-oss-laravel)\n\n这个包是封装 [aliyun-oss-flysystem](https://github.com/alphasnow/aliyun-oss-flysystem) 到 Laravel 来作为 Storage 使用.  \n如果需要客户端直传, 可使用 Web服务端签名直传OSS扩展包 [aliyun-oss-appserver](https://github.com/alphasnow/aliyun-oss-appserver)  \n\n## 版本兼容\n\n| laravel      | aliyun-oss-laravel | driver | readme |\n|:-------------|:-------------------|:-------|:-------|\n| \\\u003e=5.5,\\\u003c9.0 | ^3.0               | aliyun | [readme](https://github.com/alphasnow/aliyun-oss-laravel/blob/3.x/README-CN.md) |\n| \\\u003e=9.0       | ^4.0               | oss    | [readme](https://github.com/alphasnow/aliyun-oss-laravel/blob/4.x/README-CN.md) |\n\n## 安装依赖\n1. 通过composer管理您的项目依赖，可以在你的项目根目录运行：  \n    ```bash\n    composer require alphasnow/aliyun-oss-laravel\n    ```\n    然后通过`composer install`安装依赖。\n2. 修改环境配置 `.env`\n    ```env\n    OSS_ACCESS_KEY_ID=\u003c必填, 阿里云的AccessKeyId\u003e\n    OSS_ACCESS_KEY_SECRET=\u003c必填, 阿里云的AccessKeySecret\u003e\n    OSS_BUCKET=\u003c必填, 对象存储的Bucket\u003e\n    OSS_ENDPOINT=\u003c必填, 对象存储的Endpoint\u003e\n    ```\n3. (可选) 修改文件配置 `config/filesystems.php`\n    ```php\n    \"default\" =\u003e env(\"FILESYSTEM_DRIVER\", \"oss\"),\n    // ...\n    \"disks\"=\u003e[\n        // ...\n        \"oss\" =\u003e [\n            \"driver\"            =\u003e \"oss\",\n            \"access_key_id\"     =\u003e env(\"OSS_ACCESS_KEY_ID\"),           // 必填, 阿里云的AccessKeyId\n            \"access_key_secret\" =\u003e env(\"OSS_ACCESS_KEY_SECRET\"),       // 必填, 阿里云的AccessKeySecret\n            \"bucket\"            =\u003e env(\"OSS_BUCKET\"),                  // 必填, 对象存储的Bucket, 示例: my-bucket\n            \"endpoint\"          =\u003e env(\"OSS_ENDPOINT\"),                // 必填, 对象存储的Endpoint, 示例: oss-cn-shanghai.aliyuncs.com\n            \"internal\"          =\u003e env(\"OSS_INTERNAL\", null),          // 选填, 内网上传地址,填写即启用 示例: oss-cn-shanghai-internal.aliyuncs.com\n            \"domain\"            =\u003e env(\"OSS_DOMAIN\", null),            // 选填, 绑定域名,填写即启用 示例: oss.my-domain.com\n            \"is_cname\"          =\u003e env(\"OSS_CNAME\", false),            // 选填, 若Endpoint为自定义域名，此项要为true，见：https://github.com/aliyun/aliyun-oss-php-sdk/blob/572d0f8e099e8630ae7139ed3fdedb926c7a760f/src/OSS/OssClient.php#L113C1-L122C78\n            \"prefix\"            =\u003e env(\"OSS_PREFIX\", \"\"),              // 选填, 统一存储地址前缀\n            \"use_ssl\"           =\u003e env(\"OSS_SSL\", false),              // 选填, 是否使用HTTPS\n            \"throw\"             =\u003e env(\"OSS_THROW\", false),            // 选填, 是否抛出引起错误的异常,默认出现错误时,不抛出异常仅返回false\n            \"signatureVersion\"  =\u003e env(\"OSS_SIGNATURE_VERSION\", \"v1\"), // 选填, 选择使用v1或v4签名版本\n            \"region\"            =\u003e env(\"OSS_REGION\", \"\"),              // 选填, 仅在使用v4签名版本时启用, 示例: cn-shanghai\n            \"options\"           =\u003e [],                                 // 选填, 添加全局配置参数, 示例: [\\OSS\\OssClient::OSS_CHECK_MD5 =\u003e false]\n            \"macros\"            =\u003e []                                  // 选填, 添加自定义Macro, 示例: [\\App\\Macros\\ListBuckets::class, \\App\\Macros\\CreateBucket::class]\n        ],\n        // ...\n    ]\n    ```\n\n## 快速使用\n```php\nuse Illuminate\\Support\\Facades\\Storage;\n$storage = Storage::disk(\"oss\");\n```\n\n### 使用Storage方法\n#### 写入\n```php\nStorage::disk(\"oss\")-\u003eputFile(\"dir/path\", \"/local/path/file.txt\");\nStorage::disk(\"oss\")-\u003eputFileAs(\"dir/path\", \"/local/path/file.txt\", \"file.txt\");\n\nStorage::disk(\"oss\")-\u003eput(\"dir/path/file.txt\", file_get_contents(\"/local/path/file.txt\"));\n$fp = fopen(\"/local/path/file.txt\",\"r\");\nStorage::disk(\"oss\")-\u003eput(\"dir/path/file.txt\", $fp);\nfclose($fp);\n\nStorage::disk(\"oss\")-\u003eprepend(\"dir/path/file.txt\", \"Prepend Text\"); \nStorage::disk(\"oss\")-\u003eappend(\"dir/path/file.txt\", \"Append Text\");\n\nStorage::disk(\"oss\")-\u003eput(\"dir/path/secret.txt\", \"My secret\", \"private\");\nStorage::disk(\"oss\")-\u003eput(\"dir/path/download.txt\", \"Download content\", [\"headers\" =\u003e [\"Content-Disposition\" =\u003e \"attachment;filename=download.txt\"]]);\n```\n\n#### 读取\n```php\nStorage::disk(\"oss\")-\u003eurl(\"dir/path/file.txt\");\nStorage::disk(\"oss\")-\u003etemporaryUrl(\"dir/path/file.txt\", \\Carbon\\Carbon::now()-\u003eaddMinutes(30));\n\nStorage::disk(\"oss\")-\u003eget(\"dir/path/file.txt\"); \n\nStorage::disk(\"oss\")-\u003eexists(\"dir/path/file.txt\"); \nStorage::disk(\"oss\")-\u003esize(\"dir/path/file.txt\"); \nStorage::disk(\"oss\")-\u003elastModified(\"dir/path/file.txt\");\n```\n\n#### 删除\n```php\nStorage::disk(\"oss\")-\u003edelete(\"dir/path/file.txt\");\nStorage::disk(\"oss\")-\u003edelete([\"dir/path/file1.txt\", \"dir/path/file2.txt\"]);\n```\n\n#### 文件操作\n```php\nStorage::disk(\"oss\")-\u003ecopy(\"dir/path/file.txt\", \"dir/path/file_new.txt\");\nStorage::disk(\"oss\")-\u003emove(\"dir/path/file.txt\", \"dir/path/file_new.txt\");\nStorage::disk(\"oss\")-\u003erename(\"dir/path/file.txt\", \"dir/path/file_new.txt\");\n```\n\n#### 文件夹操作\n```php\nStorage::disk(\"oss\")-\u003emakeDirectory(\"dir/path\"); \nStorage::disk(\"oss\")-\u003edeleteDirectory(\"dir/path\");\n\nStorage::disk(\"oss\")-\u003efiles(\"dir/path\");\nStorage::disk(\"oss\")-\u003eallFiles(\"dir/path\");\n\nStorage::disk(\"oss\")-\u003edirectories(\"dir/path\"); \nStorage::disk(\"oss\")-\u003eallDirectories(\"dir/path\"); \n```\n\n### 使用 Macro\n#### 默认方法\n```php\nStorage::disk(\"oss\")-\u003eappendObject(\"dir/path/news.txt\", \"The first line paragraph.\", 0);\nStorage::disk(\"oss\")-\u003eappendObject(\"dir/path/news.txt\", \"The second line paragraph.\", 25);\nStorage::disk(\"oss\")-\u003eappendObject(\"dir/path/news.txt\", \"The last line paragraph.\", 51);\n\nStorage::disk(\"oss\")-\u003eappendFile(\"dir/path/file.zip\", \"dir/path/file.zip.001\", 0);\nStorage::disk(\"oss\")-\u003eappendFile(\"dir/path/file.zip\", \"dir/path/file.zip.002\", 1024);\nStorage::disk(\"oss\")-\u003eappendFile(\"dir/path/file.zip\", \"dir/path/file.zip.003\", 1024);\n\nStorage::disk(\"oss\")-\u003eprocessObject(\"dir/path/image.jpg\", \"image/resize,l_1000\");\n```\n\n#### 自定义 Macro\n1. 开发 Macro\n    ```php\n    namespace App\\Macros;\n    use AlphaSnow\\LaravelFilesystem\\Aliyun\\Macros\\AliyunMacro;\n    \n    class ListBuckets implements AliyunMacro\n    {\n        // ... \n    }\n    ```\n    参考实例代码: [AppendObject.php](https://github.com/alphasnow/aliyun-oss-laravel/blob/4.5.0/src/Macros/AppendObject.php)\n2. 修改配置\n    ```php\n    [\n        \"macros\" =\u003e [\\App\\Macros\\ListBuckets::class]\n    ]\n    ```\n3. 使用 Macro\n    ```php\n    Storage::disk(\"oss\")-\u003elistBuckets()\n    ```\n\n### 使用 OssClient\n```php\nuse AlphaSnow\\LaravelFilesystem\\Aliyun\\OssClientAdapter;\n\n$adapter = new OssClientAdapter(Storage::disk(\"oss\"));\n$adapter-\u003eclient()-\u003eappendObject($adapter-\u003ebucket(), $adapter-\u003epath(\"dir/path/file.txt\"), \"contents\", 0, $adapter-\u003eoptions([\"visibility\" =\u003e \"private\"]));\n```\n\n## 文档\n[阿里云 对象存储 OSS文档](https://help.aliyun.com/zh/oss/)\n\n## 问题\n如使用中遇到问题，[提交 Issue](https://github.com/alphasnow/aliyun-oss-laravel/issues)\n\n## 贡献者\n\u003ca href=\"https://github.com/alphasnow/aliyun-oss-laravel/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=alphasnow/aliyun-oss-laravel\" /\u003e\n\u003c/a\u003e\n\n## Star\n[![Star History Chart](https://api.star-history.com/svg?repos=alphasnow/aliyun-oss-laravel\u0026type=Timeline)](https://star-history.com/#alphasnow/aliyun-oss-laravel\u0026Timeline)\n\n## 授权\n[MIT](LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphasnow%2Faliyun-oss-laravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falphasnow%2Faliyun-oss-laravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphasnow%2Faliyun-oss-laravel/lists"}