Streaming upload from NodeJS to Dropbox

Our system needs to use out internal security checks when interacting with dropbox, we can therefore not use the clientside SDK for Dropbox.

We would rather upload to our own endpoint, apply security checks, and then stream the incoming request to dropbox.

I am coming up short here as there was an older NodeJS Dropbox SDK which supported pipes, but the new SDK does not. Old SDK: https://www.npmjs.com/package/dropbox-node

We want to take the incoming upload request and forward it to dropbox as it comes in. (and thus prevent the upload from taking twice as long if we first upload the entire thing to our server and then upload to dropbox)

Is there any way to solve this?


My Dropbox NPM module (dropbox-v2-api) supports streaming. It's based on HTTP API, so you can take an advantage of streams. Example? I see it this way:

const contentStream = fs.createReadStream('file.txt');
const securityChecks = ... //your security checks

const uploadStream = dropbox({
    resource: 'files/upload',
    parameters: { path: '/target/file/path' }               
}, (err, result, response) => {
    //upload finished
});

contentStream
    .pipe(securityChecks)
    .pipe(uploadStream);

Full stream support example here.

链接地址: http://www.djcxy.com/p/69088.html

上一篇: 在金字塔中调用另一种观点

下一篇: 从NodeJS上传上传到Dropbox