I download the file through Dropbox API at the server side of my app in the following manner:
// setting variable for buffering
let fileBuffered = '';
// authentication
const dropbox = dropboxV2Api.authenticate({
token: process.env.DEV_DROPBOX_SECRET_KEY
});
// configuring parameters
const params = Object.freeze({
resource: "files/download",
parameters: {
path: `/${customerFileFolder}/${fileName}`
}
});
// download
let dropboxPromise = new Promise(function (resolve, reject) {
dropbox(params, function (err, result) {
if (err) {
reject(err);
} else {
resolve(result);
}
}).on('data',function(data) {
fileBuffered += data;
})
At the end of the process I get the content of the PDF file that I'm trying to download in the fileBuffered variable. The lenght of the string (132,596 bytes) in the variable is pretty equal to the size of my PDF file (139,694 bytes). That's what I get in the debugger:

Now I need to download the file to a client. I assume that the file is binary and I have to convert it into base64.
// convert to base64
const file = `data:application/pdf;base64, ${Buffer.from(downloadResult.fileBuffered).toString("base64")}`;
res.setHeader("Content-Type", "application/pdf");
res.setHeader("Accept-Encoding", "base64");
res.send(file);
I get a much bigger file (252,678 bytes) on a client side and it opens as empty file in Acrobat Reader. What I'm doing wrong?