In my Micronaut application I have to inject the csv data in the sqllite db. Currently I have created a script which calls the endpoint like this:
curl -v -X POST "http://hostname:3030/inject"
It's picking a csv file already available at server and injecting it in sqllite db but I want to pass the csv file to the endpoint itself and want to receive it at server side using Rxjava Flowable with something like this:
updateDb(@Body Flowable<String> content) {
//saveFlowableToFile(path, content);
//pick the path to load the data
...
}
I have tried to find out documentation on how to do this but couldn't succeed.
Can anyone please suggest if it's the right way to upload a 20MB csv file and inject or there is a better way to do it.
Thanks,
The cleanest solution for big files should be to stream the data directly into Sqlite.
https://docs.micronaut.io/latest/guide/index.html#binding (Stream Support)
@Post(value = "/upload", processes = [MediaType.TEXT_PLAIN])
@ExecuteOn(TaskExecutors.IO)
fun read(@Body inputStream: InputStream) {
BufferedReader(InputStreamReader(inputStream))
...for every line in the buffered reader, parse CSV and insert to SQLite...
}
The whole point of streaming is to not have the full representation of the file in memory at any point in time, so your solution with saving to disk and then picking it up again seems not optimal.
This might also be possible with Reactive, but I can´t contribute on that topic.