GithubHelp home page GithubHelp logo

alphasnow / aliyun-oss-appserver Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 3.0 352 KB

Aliyun oss signature direct transmission. 阿里云服务端签名直传OSS扩展包.

Home Page: https://alphasnow.github.io/aliyun-oss-appserver/

License: MIT License

PHP 100.00%
aliyun-oss-appserver aliyun-oss appserver oss aliyun aliyun-sdk laravel-package

aliyun-oss-appserver's Introduction

English | 简体中文

AliYun OSS AppServer

aliyun-oss-appserver

Upload data to OSS through Web applications. Add signatures on the server, configure upload callback, and directly transfer data.

Latest Stable Version Total Downloads License Tests

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

  1. 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
  2. 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");

Ali document

https://www.alibabacloud.com/help/en/object-storage-service/latest/obtain-signature-information-from-the-server-and-upload-data-to-oss

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.