I have an application in node js in which I am uploading the image to the node server after that I compress the file to reduce the size. After that, I upload it to dropbox but the uploaded file has a 0-byte size. I don't understand the problem. Below is the code that I used.
var dir ="C:\\Users\\uploads\\converted\\"+foldername;
fs.readdir("C:\\Users\\uploads\\converted\\"+foldername, function (err, files) {
//handling error
if (err) {
return console.log('Unable to scan directory: ' + err);
}
else {
//listing all files using forEach
files.forEach(function (file) {
console.log(file);
var dbx = new Dropbox({ accessToken: 'xxxx' });
dbx.filesUpload({path: '/'+link+'/'+file , contents: file.data})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.error(error);
});
});
}
});
-------------Update after trying code---------------------
Thank you for your solution. I tried this code with changes but this time even the image file is not uploaded to dropbox. Please find my updated code below.
var namefile= path.basename("C:\\Users\\uploads\\converted\\"+foldername+"\\"+req.file.originalname,".ARW" );
var image =namefile+".dng";
fs.readFile("C:\\Users\\uploads\\converted\\"+foldername+"\\"+image, function(err, data) {
var dbx = new Dropbox({ accessToken: 'XXXX' });
dbx.filesUpload({path: '/'+link+'/'+image, contents: data})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.error(error);
});
});
Appreciate your help.