How to using req.urlencoded to read form body and return as a json data ? #182
return data |
Answered by
kartikk221
Jul 25, 2023
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! |
0 replies
Answer selected by
kartikk221
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to 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!