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.
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
}
}
package(url: "https://github.com/vapor/vapor.git", from: "3.1.0")
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
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: