Hi, I'm very new to web development so this is a v...
# ktor
m
Hi, I'm very new to web development so this is a very noob question. I'm trying to make a page where user can upload a file, then that file is processed and user gets output file for download. I can't find any info on how to achieve that (probably because I don't know what terms to use for search). Here's pseudo code of what I'm trying to do:
Copy code
fun Route.handleFile() {
    post("/handleFile") {
        call.respondTextWriter {
            appendln("Writing some output while file is being processed")
            // Handle file that will create another file for user to download
            call.respondFile(outputFile) // I know I cannot do this
        }
    }
}
Basically I want to run a long running task and show some text to the user about the progress and then after it finished that output file should be downloaded. Is that even possible to do just within ktor?
m
You might want to look into SSE or WebSockets to communicate progress.
m
Just to clarify. This is a server app. • User opens website on a browser • Uploads a file • While file is being processed user sees progress/log • When file finishes processing, result file should trigger to download automatically
m
Yes. SSE or WS are tools you could use to send progress updates to the browser.
m
OK I will look into these. Thanks. Can I use same thing for triggering file download for the user?
m
It’s up to the code running in the browser to decide what to do. Certainly possible you could send a “File’s done, here’s the ID/URL/whatever” event, and you could handle that by displaying a button to download the file.
m
Cool. Thanks very much for the pointers!
Another question: Is it possible to respond with file and HTML at the same time? Like
call.respondFileAndHtml(file) { HTML }
?
m
I doubt it. What Content-Type would you send such a response as?
m
well I;m just trying to see how to achieve: • Show some HTML or text • After a while send file
l
Could you show your HTML content and then perform a redirect? https://ktor.io/servers/calls/responses.html#redirections