I have always sent files along with form data by having the action attribute and multipart enctypes to my html forms. Recently I needed to use fetch to send a form and used the new FormData()
can read all my fields and file of a given html form. But on the nodejs
end, req.files returns null
. When I use form action
attribute, it works perfectly.
Client End
let formData = new FormData(document.getElementById('additem'));
let response = await fetch(`${window.location.href}/inventory`, {
method: "POST",
body: formData
});
On the server end I am just using express-bodyparser
(which is default now) and am trying to access the files with req.files
;
I know I can use multer
or formidable
but I was wondering if there's a way to make it work with what I have atm.
Thanks.