How to using req.urlencoded to read form body and return as a json data ? #182
-
return data
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi, Request.urlencoded() only supports urlencoded bodies. For example: "key1=value1&key2=value2". In your case, you are trying to send what seems like multipart FormData. There is a multipart parser in hyper-express for form file uploading which can be used with Request.multipart() see docs for proper usage. If the above does not work for some reason, you always have the option to do Request.text() to get the body as a raw string and then use any NPM package like https://www.npmjs.com/package/parse-multipart-data to parse it. Hope the above helps! |
Beta Was this translation helpful? Give feedback.
Hi, Request.urlencoded() only supports urlencoded bodies. For example: "key1=value1&key2=value2".
In your case, you are trying to send what seems like multipart FormData. There is a multipart parser in hyper-express for form file uploading which can be used with Request.multipart() see docs for proper usage.
If the above does not work for some reason, you always have the option to do Request.text() to get the body as a raw string and then use any NPM package like https://www.npmjs.com/package/parse-multipart-data to parse it.
Hope the above helps!