Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alex1990/tiny-oss
A tiny aliyun oss sdk for browser which focus on uploading.
https://github.com/alex1990/tiny-oss
aliyun oss
Last synced: about 2 months ago
JSON representation
A tiny aliyun oss sdk for browser which focus on uploading.
- Host: GitHub
- URL: https://github.com/alex1990/tiny-oss
- Owner: Alex1990
- License: mit
- Created: 2019-06-11T15:39:50.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-01-18T15:29:23.000Z (almost 4 years ago)
- Last Synced: 2024-09-30T19:49:30.625Z (3 months ago)
- Topics: aliyun, oss
- Language: JavaScript
- Homepage:
- Size: 42 KB
- Stars: 28
- Watchers: 1
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tiny-oss
A tiny aliyun oss sdk for browser which focus on uploading. Less than 10kb (min+gzipped).
**English | [简体中文](README_zh-CN.md)**
## Installation
Npm
```sh
npm install tiny-oss
```Yarn
```sh
yarn add tiny-oss
```## Usage
### Basic
```js
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:
```js
// Upload progress
oss.put('hello-world', blob, {
onprogress (e) {
console.log('total: ', e.total, ', uploaded: ', e.loaded);
}
});
```More options or methods see [API](#api).
## Compatibility
This package depends on some modern Web APIs, such as [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob), [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), [FileReader](https://developer.mozilla.org/en-US/docs/Web/API/FileReader), [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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](https://github.com/stefanpenner/es6-promise)**.
## API
```js
new TinyOSS(options)
```### options
Please check [Browser.js offical document](https://help.aliyun.com/document_detail/64095.html?spm=a2c4g.11186623.6.1122.27976928XhTpTr).
* 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](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/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