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