node.js - request command equivalent to cURL command not working -
curl command:
curl -f "json_query=</users/somename/desktop/api/payload/upload_image_payload.json" -f "file=@/users/somename/desktop/api/payload/image.png" http://url/api/upload_outgoing_media.php
node.js command:
var options = { method: 'post', url: 'http://url/api/upload_outgoing_media.php', headers: { 'content-type': 'multipart/form-data; boundary=----webkitformboundary7ma4ywxktrzu0gw' }, formdata: { json_query: { value: 'fs.createreadstream("/users/somename/desktop/api/payload/upload_image_payload.json")', options: { filename: '/users/somename/desktop/api/payload/upload_image_payload.json', contenttype: null } } }, file: { value: 'fs.createreadstream("/users/somename/desktop/api/payload/image.png")', options: { filename: '/users/somename/desktop/api/payload/image.png', contenttype: null } }, }; console.log("second") request(options, function (error, response, body) { if (error) throw new error(error); console.log(response.body); });
expected output: {"meta":null,"payload":{"filename":"image.png"},"error":false}
returned output: {"meta":null,"payload":null,"error":{"errortext":"no data","errorcode":null}}
found solution.
the
"<"
in curl query load contents of json file , not json file , in node query must :-
json_query: jsondata --> json file data
formdata: { json_query: jsondata, file: { value: 'fs.createreadstream("/users/somename/desktop/api/payload/image.png")', options: { filename: '/users/somename/desktop/api/payload/image.png', contenttype: null } } }};
this worked , returning expected output.
Comments
Post a Comment