forked from djyde/earthlivejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.js
43 lines (37 loc) · 883 Bytes
/
upload.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
var qiniu = require('node-qiniu')
if (process.env.NODE_ENV === 'production') {
qiniu.config({
access_key: process.env.QINIU_AK,
secret_key: process.env.QINIU_SK
})
} else {
var config = require('./config')
qiniu.config({
access_key: config.AK,
secret_key: config.SK
})
}
var imagesBucket = qiniu.bucket('himawari8')
module.exports = function (stream, path) {
return new Promise((resolve, reject) => {
var puttingStream = imagesBucket.createPutStream(path);
stream.pipe(puttingStream)
.on('error', err => {
reject(err)
})
.on('end', reply => {
resolve(reply)
})
})
}
module.exports = function (key, path) {
return new Promise((resolve, reject) => {
imagesBucket.putFile(key, path)
.then(reply => {
resolve(reply)
})
.catch(err => {
reject(err)
})
})
}