Я пытаюсь загрузить csv-файл в приложение ktor, и я использовал многочастный пример из документации ktor. Моя проблема в том, что я не вижу, как я могу вызвать / прочитать этот файл в моей программе, чтобы иметь возможность использовать CSVReaderBuilder () на нем. Моя цель - объявить переменную, сохранить в ней файл и затем использовать его для чтения содержимого. У меня есть снип-код, и если понадобятся дополнительные спецификации, я с радостью его откорректирую. Спасибо тебе
val multipart = call.receiveMultipart()
multipart.forEachPart { part ->
when (part) {
// if part is a file (could be form item/text)
is PartData.FileItem -> {
// retrieve file name of upload
val ext = File(part.originalFileName).extension
val file = File("resources/myFile.csv")
part.streamProvider().use { its ->
// copy the stream to the file with buffering
file.outputStream().buffered().use {
// note that this is blocking
its.copyTo(it)
}
}
}
}
// make sure to dispose of the part after use to prevent leaks
part.dispose()
}
// Remove the .withCSVParser part if you use the default separator instead of ";"
// This is where i want to put the uploaded File and not the path of the file
val csvReader = CSVReaderBuilder(File("resources/myFile.csv").reader(Charsets.UTF_8))
.withCSVParser(CSVParserBuilder().withSeparator(';').build())
.build()