Home > Blockchain >  How to fix bad request error while sending formdata to api in nodejs?
How to fix bad request error while sending formdata to api in nodejs?

Time:01-25

I'm getting the files to upload and other information using useform. and I log the information I receive to the screen and it does not come up null or undefined. it seems to be working correctly. but I could not send to api side. I get either 500 error or 400.

FRONTEND:

//index.js
function uploadFile(form) {

    const { email, description, files } = form;
    const formData = new FormData();
    Array.from(files).forEach((file) => {
        formData.append(file.name, file);
    });
   formData.append("email", email);
   formData.append("token", token)

   for (var key of formData.entries()) {
       console.log(key[0]   ", "   key[1]);
   }

   dispatch(uploadChallengeThunk(formData));

}

//service.js
export async function uploadChallengeService(formData) {
  Array.from(formData).forEach((item) => {
    console.log("           
  • Related