https://kotlinlang.org logo
#ktor
Title
# ktor
j

Jonathan De Leon

07/11/2022, 4:48 PM
Is there a way to limit the file upload size using multipart with
ktor-server
? I'm using
1.6.8
.
a

Aleksei Tirman [JB]

07/12/2022, 11:47 AM
This answer should help.
j

Jonathan De Leon

07/14/2022, 12:02 AM
yep thank you, I did end up finding that stackoverflow. Created a plugin that would process the
MultipartData
to find the file and read the input. Tricky part was figuring out a way to read but also let other interceptors (plugins) have access to the parts. This was necessary since once you read the parts i.e.
readAllParts()
you cannot re-read them. In addition, once you
receiveMultipart
you cannot do it again unless you add the
DoubleReceive
plugin. Lots of different caveats in order to determine the file size. Most server engines (Netty, Tomcat, etc) process the file, so it wouldn't be too difficult to add an engine configuration similar to how Spring does it.
123 Views