How to read form parameters with helidon-se 4? #7915
-
how to resolve http request form with content type of 'x-www-form-urlencoded' and 'multipart/form-data' ? |
Beta Was this translation helpful? Give feedback.
Answered by
romain-grecourt
Oct 31, 2023
Replies: 1 comment
-
Form parameters can be processed like this: Parameters parameters = request.content().as(Parameters.class); E.g. routing.post("/form-params", (req, res) -> {
Parameters parameters = req.content().as(Parameters.class);
res.send("value of 'foo': " + parameters.get("foo"));
}) Multipart can be processed like this: MultiPart mp = req.content().as(MultiPart.class); E.g. routing.post("/multipart", (req, res) -> {
MultiPart mp = req.content().as(MultiPart.class);
while (mp.hasNext()) {
ReadablePart part = mp.next();
if ("file[]".equals(part.name())) {
try (InputStream in = part.inputStream()) {
// ...
} catch (IOException e) {
throw new RuntimeException("Failed to write content", e);
}
}
}
}) See a working example at https://github.com/helidon-io/helidon/tree/4.0.0/examples/media/multipart |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sixwaaaay
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Form parameters can be processed like this:
E.g.
Multipart can be processed like this:
E.g.