alphasnow / aliyun-oss-appserver
upload data to OSS through web applications
Installs: 6 944
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 1
Forks: 3
Open Issues: 0
Requires
- php: ^7.2.5|^8.0
- ext-curl: *
- ext-json: *
- ext-openssl: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4
- mockery/mockery: ^1.3
- orchestra/testbench: ^4.18
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^8.5.23
README
English | 简体中文
AliYun OSS AppServer
Upload data to OSS through Web applications. Add signatures on the server, configure upload callback, and directly transfer data.
Installation
composer require alphasnow/aliyun-oss-appserver
Configuration
Modify the environment file .env
OSS_ACCESS_KEY_ID=<Your aliyun accessKeyId, Required, Example: LT************Hz> OSS_ACCESS_KEY_SECRET=<Your aliyun accessKeySecret, Required, Example: Q5**************************PD> OSS_BUCKET=<Your oss bucket name, Required, Example: x-storage> OSS_ENDPOINT=<Your oss endpoint domain, Required, Example: oss-cn-hangzhou.aliyuncs.com> OSS_SSL=<Whether to use ssl, Optional, Example: true> OSS_DOMAIN=<Domain name addresses, Optional, Example: x-storage.domain.com> OSS_CALLBACK_URL=<Default callback address, Optional, Example: https://api.domain.com/callback> OSS_POLICY_MAX_SIZE=<Default maximum file size 1GB, Optional, Example: 1048576000> OSS_POLICY_EXPIRE_TIME=<Default expiration time 1 hour, Optional, Example: 3600> OSS_POLICY_USER_DIR=<Default Upload Directory upload/, Optional, Example: upload/>
(Optional) Modify the config file config/oss-appserver.php
php artisan vendor:publish --provider=AlphaSnow\OSS\AppServer\Laravel\ServiceProvider
Usage
OSS configuration
- CORS configuration / Create rule / Example:
Soucre: *, Allow Methods: POST
Laravel server
Add route routes/api.php
, Use the default controller.
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 client
- Download https://www.alibabacloud.com/help/en/object-storage-service/latest/add-signatures-on-the-client-by-using-javascript-and-upload-data-to-oss#title-l7m-nho-uap
- Find line 30 of
upload.js
and change it to the actual server address, example:http://laravel.local
// serverUrl = "http://88.88.88.88:8888" serverUrl = "http://laravel.local/api/app-server/oss-token"
Examples
Example of single-file services with clients
Dynamic configuration
use AlphaSnow\OSS\AppServer\Factory; $token = (new Factory($config))->makeToken(); // Change the address of the direct transmission server $token->access()->setOssHost("https://bucket.endpoint.com"); // Change the upload directory/timeout period to 60 seconds/maximum file limit to 500 MB $token->policy()->setUserDir("upload/")->setExpireTime(60)->setMaxSize(500*1024*1024); // Change the callback address/callback body/callback header $token->callback()->setCallbackUrl("http://domain.com/oss-callback") ->setCallbackBody("filename=\${object}&size=\${size}&mimeType=\${mimeType}&height=\${imageInfo.height}&width=\${imageInfo.width}") ->setCallbackBodyType("application/x-www-form-urlencoded");