1 Star 1 Fork 1

悠悠山雨 / aliyun-oss-appserver

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

English | 简体中文

AliYun OSS AppServer

Web端直接上传数据至OSS, 服务端签名直传并设置上传回调.

Latest Stable Version Total Downloads License Test

安装依赖

composer require alphasnow/aliyun-oss-appserver

服务配置

修改环境配置 .env

OSS_ACCESS_KEY_ID=<必填, 阿里云的AccessKeyId, 示例: LT************Hz>
OSS_ACCESS_KEY_SECRET=<必填, 阿里云的AccessKeySecret, 示例: Q5**************************PD>
OSS_BUCKET=<必填, 对象存储的Bucket, 示例: my-files>
OSS_ENDPOINT=<必填, 对象存储的Endpoint, 示例: oss-cn-hangzhou.aliyuncs.com>
OSS_CALLBACK_URL=<选填, 默认回调地址, 示例: https://my-domain.com/callback>
OSS_POLICY_MAX_SIZE=<选填, 默认最大文件大小1000MB, 示例: 1048576000>
OSS_POLICY_EXPIRE_TIME=<选填, 默认过期时间3600秒, 示例: 3600>
OSS_POLICY_USER_DIR=<选填, 默认上传目录upload/, 示例: upload/>

(可选) 修改配置文件 config/oss-appserver.php

php artisan vendor:publish --provider=AlphaSnow\OSS\AppServer\ServiceProvider

快速使用

Laravel服务端

添加路由routes/api.php, 使用默认控制器.

Route::get("app-server/oss-token", "\AlphaSnow\OSS\AppServer\Laravel\ServerController@token");
Route::post("app-server/oss-callback", "\AlphaSnow\OSS\AppServer\Laravel\ServerController@callback");

Web客户端

  1. 下载 https://help.aliyun.com/document_detail/31927.html#section-kx3-tsk-gfb
  2. 找到upload.js的第30行代码,修改为实际服务器地址
    // serverUrl = "http://88.88.88.88:8888"
    serverUrl = "http://laravel.local/api/app-server/oss-token"
  3. OSS对象存储的对应bucket设置Cors(Post打勾)

示例

单文件服务与客户端的示例

动态配置

use AlphaSnow\OSS\AppServer\Factory;

$token = (new Factory($config))->makeToken();

// 修改直传服务器地址
$token->access()->setOssHost("https://bucket.endpoint.com");

// 修改上传目录/超时时间60秒/最大文件限制500M
$token->policy()->setUserDir("upload/")->setExpireTime(60)->setMaxSize(500*1024*1024);

// 修改回调地址/回调数据/回调请求头
$token->callback()->setCallbackUrl("http://domain.com/callback")
    ->setCallbackBody("filename=\${object}&size=\${size}&mimeType=\${mimeType}&height=\${imageInfo.height}&width=\${imageInfo.width}")
    ->setCallbackBodyType("application/x-www-form-urlencoded");

阿里云文档

https://help.aliyun.com/document_detail/31927.html

MIT License Copyright (c) 2022 Alpha Snow Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

客户端直传阿里云OSS扩展包 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/shanyu/aliyun-oss-appserver.git
git@gitee.com:shanyu/aliyun-oss-appserver.git
shanyu
aliyun-oss-appserver
aliyun-oss-appserver
1.x

搜索帮助