cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Excel files uploaded to Dropbox using Node.js SDK are invalid

Excel files uploaded to Dropbox using Node.js SDK are invalid

annahernandez99
Explorer | Level 4

I am trying to upload Excel files to Dropbox using the Node.js SDK (https://github.com/dropbox/dropbox-sdk-js). The files are received from JsReport, and are saved correctly when saved to my local disk. However, when uploading to Dropbox, the files end up long strings instead of Excel files.

The body in this case is a string that gets encoded to base64. The filename is speedtest_daily_2021-01-15_test26.xlsx.

This line writes the file successfully to my local drive:

fs.writeFileSync(*filename*, body, {encoding: 'base64'});
This is the code I'm using to upload the file to Dropbox:

body = Buffer.from(body).toString('base64');

dbx.filesUpload({ contents: body, path: saveLocation + `/` + filename })
.then((response: any) => {
console.log(`Saved file "${filename}" to Dropbox folder ${saveLocation}`);
}).catch((uploadErr: DropboxError<files.UploadError>) => {
console.log(uploadErr);
});
This is how the Excel file should look, and looks on my local:

dropbox01.png

This is what happens when I open the Dropbox Excel file:

dropbox02.png

This is how the Dropbox file looks when I open it up in a text editor:

dropbox03.png

I've tried various encoding combinations for Dropbox but none of them seem to work. tell me what i should do

1 Reply 1

Greg-DB
Dropbox Staff

When uploading files to Dropbox, you should upload the raw data itself, without any additional encoding. It appears you're uploading the data with base64 encoding in this case though, and so the uploaded data has that additional encoding. You should perform the upload without that base64 encoding.

 

Here's an example of uploading a local file to Dropbox using the Dropbox API v2 JavaScript SDK in Node.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?