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
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))
.
使用 JSON.stringify 发送对象,然后在收到数据后使用 JSON.parse,使字符串对象再次成为对象。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.