File Uploads via Dropbox Api V2

后端 未结 2 538
野的像风
野的像风 2021-01-21 08:16

Previously I was using the Dropbox API V1 within my web app to upload files my dropbox account. Please note that the app uses only one dropbox account (mine) to

2条回答
  •  别那么骄傲
    2021-01-21 08:34

    I encourage you to use existing nodejs dropbox packages, which hides abstraction of an authentication process, etc. under the hood.

    Check official dropbox-sdk-js or try my tiny package dropbox-v2-api. Quick example:

    const dropboxV2Api = require('dropbox-v2-api');
    
    //create session
    const dropbox = dropboxV2Api.authenticate({
        token: 'TOKEN HERE'
    });
    
    //create upload stream
    const uploadStream = dropbox({
        resource: 'files/upload',
        parameters: {
            path: '/dropbox/path/to/file.txt'
        }
    }, (err, result) => {
        // upload completed
    });
    
    //use nodejs stream
    fs.createReadStream('path/to/file.txt').pipe(uploadStream);
    

提交回复
热议问题