-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstream-dropbox-to-gdrive.js
47 lines (43 loc) · 1.07 KB
/
stream-dropbox-to-gdrive.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
var compose = require('../').extend({
Request: {multipart: require('request-multipart')}
})
var download = ({token, file}) =>
compose.stream({
url: 'https://content.dropboxapi.com/2/files/download',
headers: {
'authorization': `Bearer ${token}`,
'Dropbox-API-Arg': JSON.stringify({path: `/${file}`}),
}
})
var upload = ({token, file, body}) =>
compose.client({
method: 'POST',
url: 'https://www.googleapis.com/upload/drive/v3/files',
qs: {uploadType: 'multipart'},
headers: {authorization: `Bearer ${token}`},
multipart: [
{
'Content-Type': 'application/json',
body: JSON.stringify({name: file}),
},
{
'Content-Type': 'image/png',
body,
}
]
})
;(async () => {
var auth = {
dropbox: '[ACCESS TOKEN]',
gdrive: '[ACCESS TOKEN]',
}
var file = 'cat.png'
try {
var {res:body} = await download({token: auth.dropbox, file})
var {body:meta} = await upload({token: auth.gdrive, file, body})
console.log(meta)
}
catch (err) {
console.error(err)
}
})()