node.js - Posted file has headers added to file content -


i trying post files server. returns 200 ok response, content of files not readable programs. when open in text file, see boundary , headers present in content of file.

file starts ----------------------------802523244934076832438189 content-disposition: form-data; name="file"; filename="test1.png" content-type: image/png  , ends ----------------------------802523244934076832438189-- 

my code given below:

 var formdata = {         file:{             value: fs.createreadstream('./upload-folder/' + filename),             options: {                 filename: filename,                 contenttype: req.body.attachment.mimetype //mimetype json             }         }     };     var options = {         url: config.deployment.incidenturl  + '/attachment?filename=' + filename,         method: "post",         headers: { contenttype: "application/json"},         json: true,         formdata: formdata     };  request(options,             function (error, response, body) {                 if (error) {                     errorlog.error(`error message : postattachmenttocsms : ${error}`);                 }                 else {                     successlog.info(`attachment posted correlation id: ${coridfromjira}`);                 }             }); 

i think it's because using formdata mutually exclusive using json: true: data either multipart/form-data encoded or json-encoded, can't both. content-type header isn't correct (although it's misspelled technically not problem).

try this:

var options = {   url: config.deployment.incidenturl  + '/attachment?filename=' + filename,   method: "post",   formdata: formdata }; 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -