Skip to content Skip to sidebar Skip to footer

Upload Image In React Does Not Return Form Data Values

I want to get form data values uploading images. Trying to access console.log('formadata values', fd); i don't get anything there. Question: How to get form data using my code? de

Solution 1:

to see the values in the FormData you must use loop like below:

for (let value of fd.values()) {
   console.log(value);
}

you can also see the value of a certain data by using the key :

console.log(fd.get('key'));

Also be careful for append multi files by a key (in your code = "upload") in loop, your data will override and just one of them append in the end, for uploading multi files by an input you must use the [] after the name of input like below:

const getFileList = e.fileList.map((i) => {
   return fd.append("upload[]", i.originFileObj);
});

Post a Comment for "Upload Image In React Does Not Return Form Data Values"