We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
Inter80801
6 years agoExplorer | Level 3
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
1 Reply
- Greg-DB6 years ago
Dropbox Community Moderator
[ 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.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 3 hours ago
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!