Im using DropBox API to upload files. To upload files to Dropbox, I go through the following steps:
- First upload the file from
form to a local directory on the server. - Reading a file from a local directory using
fs.createReadStream - Send the Dropbox file via the Dropbox API.
Problem:
For some reason, fs.createReadStream takes an absolute age when reading and downloading a large file. Now the file I'm trying to download is 12 MB , which is not a large file, but it takes about 18 minutes to download / process a 12 MB file .
I do not know where the problem is either in createReadStream or in the Dropbox api code.
It works with files of size within kb .
My code is:
let options = { method: 'POST', uri: 'https://content.dropboxapi.com/2/files/upload', headers: { 'Authorization': 'Bearer TOKEN HERE', 'Dropbox-API-Arg': "{\"path\": \"/test/" + req.file.originalname + "\",\"mode\": \"overwrite\",\"autorename\": true,\"mute\": false}", 'Content-Type': 'application/octet-stream' }, // I think the issue is here. body: fs.createReadStream(`uploads/${req.file.originalname}`) }; rp(options) .then(() => { return _deleteLocalFile(req.file.originalname) }) .then(() => { return _generateShareableLink(req.file.originalname) }) .then((shareableLink) => { sendJsonResponse(res, 200, shareableLink) }) .catch(function (err) { sendJsonResponse(res, 500, err) });
Update:
const rp = require('request-promise-native');
source share