Looking for some guidance on handling file uploads...
# ktor
c
Looking for some guidance on handling file uploads to my ktor server properly. I'm sending an InputStream from the client using
InputProvider() {inputStream.asInput()}
in a MultiPartFormDataContent body. Is there a way to handle the stream on the server immediately (such as piping to a file or other storage service) instead of waiting for the client to finish sending the data entirely? My initial attempt was to use
call.receiveMultipart()
and then invoke `part.streamProvider().buffered().use { //etc }`on the FileItem part. However, it seems like the call.ReceiveMultipart() waits for an entire part to be received before doing any processing on it (such as within a multipartData.forEachPart {} block)
a
Starting from Ktor 3.0.0-beta-1 the
FileItem.provider
method returns a
ByteReadChannel
, so the part's body isn't entirely read upon receipt.
c
Oh nice - that sounds promising! The multipart functions have a lot of nice features, so I'll likely switch over once there's a koin-ktor release compatible with ktor 3