I am building a web app which need to upload a test report. i am working on front end and other guy is working on backend(with nodejs and mongodb). His api server is running separately and my webapp is running separately. now i need to send the uploaded file to his api as it is. i am having a problem in doing it. I am sending data through ajax. this is my ajax code
var $form = $(e.target);
var formData = new FormData();
formData.append('productsfile', $('#prdcttestfile')[0].files[0]);
formData.append('productid', $('#prdctid').val());
formData.append('warantydays', $('#prdctwarranty').val());
formData.append('baseprice', $('#prdctbaseprice').val());
formData.append('discountedpercent', $('#prdctdiscountedprice').val());
formData.append('taxpercent', $('#prdcttax').val());
formData.append('language', $('#prdctlanguage').val());
formData.append('inventoryid', $('#village').val());
$.ajax({
url: '/product/movetoinventory',
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function (response) {
if (response.success) {
new PNotify({
title: "Enquiry Updted",
type: "info",
text: "Your enquiry has been updated",
nonblock: {
nonblock: true
},
addclass: 'dark',
styling: 'bootstrap3',
hide: true,
before_close: function (PNotify) {
PNotify.update({
title: PNotify.options.title + " - Enjoy your Stay",
before_close: null
});
PNotify.queueRemove();
return false;
}
});
$('.modal.in').modal('hide');
$("#inventory_product")[0].reset();
}
}
});
when i use console.log(req.body) in my routes i am getting the data along with the FILE PATH(not file). if i use console.log(req.files) i am getting empty {}.