Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Cap32 committed Jun 30, 2017
1 parent daa59ad commit 10d24fa
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A tiny qiniu sdk for uploading file. (browser only)
- No UI
- Support upload base64 string


## Requirements

- Qiniu developer account
Expand All @@ -26,6 +27,7 @@ Using yarn:
$ yarn add tiny-qiniu
```


## Usage

### TinyQiniu#constructor(options)
Expand All @@ -36,25 +38,29 @@ $ yarn add tiny-qiniu
import TinyQiniu from 'tiny-qiniu';

const config = {
name: 'my_bucket', // qiniu bucket name, requried
domain: 'http://cdn.awesome.com', // qiniu bucket domain, requried
bucket: 'my_bucket', // qiniu bucket name, requried
baseURL: 'http://cdn.awesome.com', // qiniu bucket domain, requried

/* one of `uptoken`, `uptokenUrl`, `uptokenFunc` is required */

// use a static uptoken string, it's NOT recommended
uptoken: 'your_upload_token',

// or use a url to dynamically get an uptoken, should return json with `{ uptoken: 'uptoken_from_server' }`
// or use an url to dynamically get uptoken, should return json with `{ uptoken: 'uptoken_from_server' }`
uptokenUrl: 'http://localhost/api/uptoken',

// or use a function to dynamically return an uptoken string.
// or use a function to dynamically return uptoken string
uptokenFunc: () => {
const fakeFetch = () => new Promise((resolve) => {
setTimeout(() => resolve('my_uptoken'), 1000)
});

return fakeFetch('/fake/api'); // return a promise
},

mapUptoken: (data) => data.uptoken || data, // Optional, a function to map uptoken when fetch uptoken completed

mapResponseURL: (url, hash, key) => url, // Optional, a function to map final url
};
const tinyQiniu = new TinyQiniu(config);
```
Expand Down Expand Up @@ -102,10 +108,10 @@ For more usage, please check the `./test` directory, or clone this repo and run

```json
{
"key": "<Your qiniu AccessKey>",
"secret": "<Your qiniu SecretKey>",
"accessKey": "<Your qiniu AccessKey>",
"secretKey": "<Your qiniu SecretKey>",
"bucket": "<Your qiniu bucket name>",
"domain": "<Your qiniu bucket domain>"
"baseURL": "<Your qiniu bucket baseURL>"
}
```

Expand Down

0 comments on commit 10d24fa

Please sign in to comment.