Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get form data from '[object Object]'

I am passing uploaded file and dataObject in FormData:

let data = new FormData();
data.append("file", this.state.files);
data.append("data", formData);

formData is just a Json Object eg: formData = { "a":123 }

Passing data to the node server using put request with axios ,I am able to get the file object and data in req, but in data field it's giving '[object Object]'

Don't know how to access this. I tried JSON.parse(req.body.data), but getting error

SyntaxError: Unexpected token o in JSON at position 1

like image 499
Prabhat Mishra Avatar asked Jul 23 '26 07:07

Prabhat Mishra


1 Answers

Looks like formData is an object that's cast to string [object Object] prior to being sent on the wire. Try data.append("data", JSON.stringify(formData)).

like image 114
Daniel Sokolowski Avatar answered Jul 24 '26 22:07

Daniel Sokolowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!