-
Notifications
You must be signed in to change notification settings - Fork 88
Open
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Currently, Kobweb servers don't have a way to handle multipart form submissions.
In ktor, this is handled with a special multipart handler:
call.receiveMultipart(formFieldLimit = 1024 * 1024 * 100).forEachPart { part ->
when (part) {
is PartData.FormItem -> { ... }
is PartData.FileItem -> { ... }
else -> { ...}
}
part.dispose()
}A few key features that need to be supported:
- Abstracting over the ktor API with a Kobweb class
- The ability to process one part at a time (using a
suspendfunction). - Recommendations for how to handle the PartData when branches but in a Kobweb way
- The ability to configure the multipart size. (If not explicitly set, defaults to 50MB)
- Disposing the parts
- (I think we can do this on behalf of the user -- why doesn't the ktor API do it though?)
The only data that we read early enough to be able to configure ktor has to live in the conf.yaml, I think, so something like this:
server:
multipart:
- api: "upload"
limit: 100mbAnd finally the handler itself, which can probably be seamlessly added to the @Api endpoint concept in Kobweb by adding a multipart property to the ApiContext class:
@Api
fun upload(ctx: ApiContext) {
ctx.multipart.forEachPart { /* how to handle formitem and fileitem etc types here?? */ }
}But I still need to investigate a little more.
Questions:
- What should happen if you call
ctx.multipartfor a route that didn't upload one? Should the field be nullable and only non-null if a multipart value is set? Should it just no-op? Should it throw an exception? - Should I try to surface all the ktor
PartDataclasses but with Kobweb wrappers? Or would it be better to be simple, where each part is just the raw binary data for that part?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Status
No status
Status
No status