Vapor: Multipart form error in post request

Created on 20 Nov 2018  Â·  3Comments  Â·  Source: vapor/vapor

Hi,
[ERROR] [HTTP] [HTTP] Request size exceeded maximum, connection closed. [HTTPServer.swift:178]
This is the error while I am trying to upload a file locally. it happen only with a relative big file, 1MB+.
The call abort in HTTPServer.swift:178 and never enter in post routing method.

Steps to reproduce

code snippet from https://docs.vapor.codes/3.0/multipart/overview/
HTML

<form method="POST" action="/users" enctype="multipart/form-data">
        <input type="text" name="name">
        <input type="text" name="age">
        <input type="file" name="image">
        <input type="submit" name="submit" value="Submit" />
    </form>

SWIFT

struct User: Content {
    var name: String
    var age: Int
    var image: Data
}

router.post("users") { req -> Future<HTTPStatus> in
            return try req.content.decode(User.self).map(to: HTTPStatus.self) { user in
                print(user.name) // "Vapor"
                print(user.age) // 3
                print(user.image) // Raw image data
                return .ok
            }
        }

Environment


package(url: "https://github.com/vapor/vapor.git", from: "3.1.0")

  • Vapor Framework version: 3.1.10
  • Vapor Toolbox version: 3.1.10
  • OS version: Mac 10.14.1 (18B75)

Most helpful comment

There is a default limit of 1 million bytes for incoming requests, which you can override by registering a custom NIOServerConfig instance – typically in your configure.swift:

services.register(NIOServerConfig.default(maxBodySize: 20_000_000))

All 3 comments

There is a default limit of 1 million bytes for incoming requests, which you can override by registering a custom NIOServerConfig instance – typically in your configure.swift:

services.register(NIOServerConfig.default(maxBodySize: 20_000_000))

@vzsg thank you, the problem was this configuration, now work, but its too slow with big files.
I tried with Postman with out modify NIOServerConfig and work and is fast.

Why an html form is too slow and need different configuration?

@vzsg I was wrong, the setting to do that you suggested is correct.
Thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mandrusiaks picture mandrusiaks  Â·  4Comments

kgn picture kgn  Â·  3Comments

Igor-Palaguta picture Igor-Palaguta  Â·  3Comments

loganwright picture loganwright  Â·  3Comments

Joannis picture Joannis  Â·  4Comments