Reputation: 173
I'm trying to use the V2 end points for file upload. I believe the content headers are set right but I keep getting this error. Can anyone help please ?
const request = require('request');
var fs = require('fs');
var apiArgs = '{ "path" : "/testfolder/Nespresso.zip", "mode" : "add", "autorename" : true, "mute" : false }' ;
var formData = {
'data-binary': fs.createReadStream("F:\\Nespresso.zip")
};
const options = {
headers: {
'Authorization' : 'Bearer ############',
'Content-Type' : 'application/octet-stream',
'Dropbox-API-Arg': apiArgs
},
formData : formData
};
request.post('https://content.dropboxapi.com/2/files/upload', options, function(err, res, body) {
//let json = JSON.parse(body);
console.log(body);
if(res)
console.log(res.statusCode);
if(err)
console.log(err);
});
Error on node :
Error in call to API function "files/upload": Bad HTTP "Content-Type" header: "m ultipart/form-data; boundary=--------------------------298294176382492406791283" . Expecting one of "application/octet-stream", "text/plain; charset=dropbox-cor s-hack". 400
Upvotes: 0
Views: 752
Reputation: 106
Not sure whether data-binary
is valid formData
property of request configuration object. See https://github.com/request/request#multipartform-data-multipart-form-uploads. What's more, Dropbox requires application/octet-stream
type data instead of multipart/form-data
as you have provided. How about:
const request = require('request');
var fs = require('fs');
const options = {
url: 'https://content.dropboxapi.com/2/files/upload',
headers: {
'Authorization' : 'Bearer ############',
'Content-Type' : 'application/octet-stream',
'Dropbox-API-Arg': JSON.stringify({
'path' : '/package.json'
})
}
};
const uploadStream = request.post(options, function(err, res, body) {
//let json = JSON.parse(body);
console.log(body);
if(res)
console.log(res.statusCode);
if(err)
console.log(err);
});
fs.createReadStream('./package.json').pipe(uploadStream);
Upvotes: 1