tiny-oss
TypeScript icon, indicating that this package has built-in type declarations

0.5.1 • Public • Published

tiny-oss

A tiny aliyun oss sdk for browser which focus on uploading. Less than 10kb (min+gzipped).

English | 简体中文

Installation

Npm

npm install tiny-oss

Yarn

yarn add tiny-oss

Usage

Basic

const oss = new TinyOSS({
  accessKeyId: 'your accessKeyId',
  accessKeySecret: 'your accessKeySecret',
  // Recommend to use the stsToken option in browser
  stsToken: 'security token',
  region: 'oss-cn-beijing',
  bucket: 'your bucket'
});

const blob = new Blob(['hello world'], { type: 'text/plain' });

// Upload
oss.put('hello-world', blob);

Upload progress

You can specify the third parameter to monitor the upload progress data:

// Upload progress
oss.put('hello-world', blob, {
  onprogress (e) {
    console.log('total: ', e.total, ', uploaded: ', e.loaded);
  }
});

More options or methods see API.

Compatibility

This package depends on some modern Web APIs, such as Blob, Uint8Array, FileReader, Promise.

So, it should work in the below browsers.

  • Chrome >= 20
  • Edge >= 12
  • IE >= 10
  • Firefox >= 4
  • Safari >= 8
  • Opera >= 11
  • Android >= 4.4.4
  • iOS >= 8

For IE and low version FireFox, you should import a promise polyfill, such as es6-promise.

API

new TinyOSS(options)

options

Please check Browser.js offical document.

  • accessKeyId
  • accessKeySecret
  • stsToken
  • bucket
  • endpoint
  • region
  • secure
  • timeout

put(objectName, blob, options)

Upload the blob.

Arguments

  • objectName (String): The object name.
  • blob (Blob|File): The object to be uploaded.
  • [options (Object)]
    • [onprogress (Function)]: The upload progress event listener receiving an progress event object as an parameter.

Return

  • (Promise)

putSymlink(objectName, targetObjectName)

Create a symlink.

Arguments

  • objectName (String): The symlink object name.
  • targetObjectName (String): The target object name.

Return

  • (Promise)

signatureUrl(objectName, options)

Get a signature url to download the file.

Arguments

  • objectName (String): The object name.
  • [options (Object)]:
    • [options.expires (Number)]: The url expires (unit: seconds).

Return

  • (String)

LICENSE

MIT

Readme

Keywords

Package Sidebar

Install

npm i tiny-oss

Weekly Downloads

33

Version

0.5.1

License

MIT

Unpacked Size

268 kB

Total Files

17

Last publish

Collaborators

  • alexchao