I've created FormData
object created like that:
var data = new FormData()
data.append('image', input[0].files[0])
data.append('user', 'hubot')
Now when i try to inspect it like that
console.log(data)
i get empty FormData
object (the only propery is __proto__
). There is no image
and user
properties.
You should have to iterate over entries . FormData
is type of object
so rather than logging itself you have to get values by get
method or iterate over entries
. Here is how.
var data = new FormData()
//data.append('image', input[0].files[0])
data.append('user', 'hubot')
for(var pair of data.entries()) {
console.log(pair[0]+ ', '+ pair[1]);
}
If you want to fetch only one value at a time , you can have by key
console.log(data.get('user'));
// 'hubot'
Edit
Spread syntax allows an iterable such as an array expression or string to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected. More from here . So if you want to simply log
// console.log(...data);
Try with this:
for (var d of data.entries()) {
console.log(d);
// Do whatever with d
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With