Jakub Gwóźdź
08/30/2022, 10:31 AMpost("/fileimport") {
val multipartData = call.receiveMultipart()
val parts = multipartData.readAllParts()
.filterIsInstance<PartData.FileItem>()
.mapIndexed { index, item ->
UploadedContent(
name = item.name ?: "unnamed$index",
filename = item.originalFileName ?: "unnamed$index",
contentType = item.contentType,
bytes = item.provider.invoke().readBytes()
)
}
doSomething(parts)
call.respond("OK")
}
so the questions is - do I need to somehow close resources created by call.receiveMultipart()
or item.provider.invoke().readBytes()
?August Lilleaas
08/30/2022, 10:44 AMCloseable
, so I guess the answer is no 🙂Jakub Gwóźdź
08/30/2022, 10:45 AM.dispose()
method but I’m not sure if this is something to be called manually, or it’s internal mechanismJakub Gwóźdź
08/30/2022, 11:09 AMbytes = item.provider.invoke().use { it.readBytes() }
🙂Aleksei Tirman [JB]
08/30/2022, 12:39 PMdispose()
method on the binary and file items to free associated resources.Aleksei Tirman [JB]
08/30/2022, 12:40 PMJakub Gwóźdź
08/30/2022, 12:48 PM