cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more 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: 

How to upload file to Dropbox with axios

How to upload file to Dropbox with axios

Inter80801
Explorer | Level 3

Since request package is depricated (https://www.npmjs.com/package/request ) I opt to use axios for interaction with Dropbox API.

I need to upload files from node.js server

I'm getting error "Request failed with status code 400". Here is my code. What I'm doing wrong?

 

const uploadToExternalService = async function uploadToExternalService(token, path, content) {
try {
let res = await axios({
url: 'https://api-content.dropbox.com/2/files/upload/',
method: 'post',
// timeout: 8000,
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'text/plain'
},
body: content
})
if(res.status == 200){
// test for status you want, etc
console.log(res.status)
}
if(res.status == 400){
// test for status you want, etc
console.log(res)
}
// Don't forget to return something
return res.data
}
catch (err) {
console.error(err);
}
}

 

uploadToExternalService(SECRET_KEY, req.file.path, req.file).then(res => console.log(res));b 

 

1 Reply 1

Greg-DB
Dropbox Staff

[ Cross-linking for reference: https://stackoverflow.com/questions/61291263/how-to-upload-file-to-dropbox-with-axios ]

 

What is in the response body for the 400 error response? It should contain a more specific and useful error message indicating what the issue is.

Need more support?
Who's talking

Top contributors to this post

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