We Want to Hear From You! What Do You Want to See on the Community? Tell us here!

Forum Discussion

Inter80801's avatar
Inter80801
Explorer | Level 3
6 years ago

How to upload file to Dropbox with axios

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 

 

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 3 hours ago
410 Following

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!