Routing-controllers: How do I receive Form Data?

Created on 20 Oct 2017  路  14Comments  路  Source: typestack/routing-controllers

There's no @Form decorator, so how does the route controller receive x-www-form-urlencoded data and inject it?

awaiting answer question

Most helpful comment

Use body-parser and you will have that data in body.

@UseBefore(bodyParser.urlencoded())
handleForm(@Body() form: any) {}

All 14 comments

Use body-parser and you will have that data in body.

@UseBefore(bodyParser.urlencoded())
handleForm(@Body() form: any) {}

how to receive body as buffer
@19majkel94

@pleerock @NoNameProvided
Should we implement an option for @Body decorator to declare the type of the body-parser method to call before action? It's inconvenient to manually do it with @UseBefore.

@19majkel94 Good idea.

Yeah it鈥檚 a good idea

Umm, @Body doesn't parse urlencoded by default?

Btw, express now has its own bodyparser, so I think we should use that, it's 1 less dep to install.

@BruceHem nope, just json/text:

if (actionMetadata.isBodyUsed) {
            if (actionMetadata.isJsonTyped) {
                defaultMiddlewares.push(this.loadBodyParser().json(actionMetadata.bodyExtraOptions));
            } else {
                defaultMiddlewares.push(this.loadBodyParser().text(actionMetadata.bodyExtraOptions));
            }
        }

Any interest in related PR? Or this is by design?

Any update on above issue? is it fixed? How can I read form url encoded values? Any help on using @UseBefore(bodyParser.urlencoded()) on controller would be helpful.

Also hoping for an update to this, ideally for the @Body() parameter to include form data automatically.

Stale issue message

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AnthoniG picture AnthoniG  路  4Comments

davidquintard picture davidquintard  路  4Comments

impzero picture impzero  路  4Comments

szabobar picture szabobar  路  4Comments

dcbartlett picture dcbartlett  路  3Comments