I have a question regarding `multipart/form-data` ...
# ktor
j
I have a question regarding
multipart/form-data
in Ktor 3.0 🧵
In Ktor 2.0, I had the following code (kind of)
Copy code
val fileProvider = getPart()?.provider
// later in the code
fileProvider?.invoke().readRemaining().readByteArray()

fun getPart(): PartData? = {
  call.receiveMultipart().forEachPart { part ->
    if (part is PartData.FileItem) return@getPart part
  }
  return null
}
This worked fine. But in Ktor 3.0 I get an empty byte array if I do this. Is Ktor 3.0 doing some automatic cleanup of stream or provider before I get to reading the data?
a
Can you please share a complete code snippet?
The problem might be due to this change.
j
Oh yeah, the addition of
Copy code
previousPart?.dispose?.invoke()
looks like it would do it. We have a try/finally that does the dispose later on.
I can add a more complete code snippet later today 🙂
a
Feel free to file an issue if you think it's a bug.
j
will do! thanks
d
Hi @Aleksei Tirman [JB], I have filed an issue related to this self-clearing of PartData. There I explain a bit why this might not be a good idea. @Jeff Hudson You might also find it interesting. https://youtrack.jetbrains.com/issue/KTOR-8125/PartData-self-clearing