Skip to content

Commit

Permalink
chore: Avoid using deprecated streamProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkleiven committed Dec 31, 2023
1 parent 3692ac3 commit 1505e7a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/ApiUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.powsybl.sld.SldParameters
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.http.content.*
import java.io.StringWriter
import java.nio.ByteBuffer

private val logger = KotlinLogging.logger {}

Expand All @@ -35,9 +36,11 @@ suspend fun multiPartDataHandler(

is PartData.FileItem -> {
val name = part.originalFileName ?: ""
val content = part.streamProvider().readBytes()
val fileContent = FileContent(name, content)
logger.info { "Received file $name with size ${content.size} bytes. Content hash: ${fileContent.contentHash()}" }
val fileSize = (part.headers["Content-Length"] ?: "0").toInt()
val buffer = ByteBuffer.allocate(fileSize)
part.provider().readFully(buffer)
val fileContent = FileContent(name, buffer.array())
logger.info { "Received file $name with size $fileSize bytes. Content hash: ${fileContent.contentHash()}" }
files.add(fileContent)
}

Expand Down

0 comments on commit 1505e7a

Please sign in to comment.