Created
October 2, 2018 20:11
-
-
Save camilomontoyau/944502e2144a20fd5e2c6996c4d3382b to your computer and use it in GitHub Desktop.
npm dropbox upload files via streams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dropboxV2Api = require('dropbox-v2-api'); | |
const path = require('path'); | |
const fs = require('fs'); | |
const {token} = process.env; | |
const dropbox = dropboxV2Api.authenticate({ | |
token | |
}); | |
const dropboxUploadStream = dropbox( | |
{ | |
resource: 'files/upload', | |
parameters: { | |
path: '/test2.txt' | |
} | |
}, | |
(err, result, response) => { | |
if (err) console.log({ err }); | |
if (result) console.log({ result }); | |
if (response) console.log({ response }); | |
} | |
); | |
fs.createReadStream(path.join(__dirname, '/test.txt')).pipe( | |
dropboxUploadStream | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment