-
Notifications
You must be signed in to change notification settings - Fork 1
/
upyun.js
48 lines (40 loc) · 966 Bytes
/
upyun.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import request from 'request';
class Upyun {
/**
*
* @param name
* @param pass
*/
constructor(user, pass,bucket) {
this.user = user;
this.pass = pass;
this.bucket=bucket;
}
/**
*
* @param part
* @param path
* @returns {Promise}
*/
upload(part, path) {
return new Promise((reslove, reject)=> {
part.pipe(request({
url: `http://v0.api.upyun.com/${this.bucket}/${path}`,
method: 'PUT',
auth: {
'user': this.user,
'pass': this.pass
}
}, function (err, response, body) {
if (err) {
return reject(err);
}
return reslove({
body: body,
response: response
});
}));
})
}
}
export default Upyun;