How can someone send json object and input file on the same request. I am familiar with this post and others.I don't use a <form> element as a parent of the <input type="file"> element but just a div. My code is like this:
var inputFiles = document.getElementById('archiveFile').files[0]
var formData = new FormData(); // Currently empty
formData.append('file[]',inputFiles,'hey.png')//append the input file
var data= { p_doc_no: "some value",
p_receive_date: "some value1",
p_thema: "some value2",
p_prot_no: "some value3",
p_sender: "some value4",
p_energeia: "some value5",
}
I have tried appending the object in the formData like this:
for ( var key in data ) {
formData.append(key, data[key]);
}
and then make the AJAX request like this:
$.ajax({
url: 'makeDBEntry/archive',
data: formData,
contentType: false,
processData: false,
type: 'POST',
success: function(data){
console.log(data);
}
});
but no luck until now. Any thoughts? At the end i need to access the request data from node js
Update Thanks to charlietfl I have found my silly solution as easy as using the multer module to handle formdata in node js