https://kotlinlang.org logo
#ktor
Title
# ktor
l

Lev Teytelman

11/01/2023, 4:41 AM
Is there a way I can override the Content-Type header in
ApplicationCall#respondFile
? It seems like using
wrapHeaders
in the
configure
block doesn't have access to the headers that are later appended, and Ktor uses an unsatisfactory way of getting the content type for me (using the file extension). I assume I would be able to emulate
respondFile
if all else fails, but that would likely mean having to handle partial gets as well and so I'd like to avoid it if possible. I'm currently getting a result like this when appending the Content-Type manually.
a

Aleksei Tirman [JB]

11/01/2023, 7:42 AM
The easiest way is to use the
LocalFileContent
class directly:
Copy code
routing {
    get {
        call.respond(LocalFileContent(File("file.jpg"), contentType = ContentType.Text.Plain))
    }
}
👍🏻 1
👍 1
2 Views