Skip to content

Commit

Permalink
fix: Content-Disposition
Browse files Browse the repository at this point in the history
  • Loading branch information
LotuxPunk committed Jul 14, 2024
1 parent fb144e6 commit 251fa54
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/main/kotlin/be/vandeas/plugins/Routing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,20 @@ fun Application.configureRouting() {
is FileReadResult.Failure -> call.respond(HttpStatusCode.InternalServerError, result.message)
is FileReadResult.NotFound -> call.respond(HttpStatusCode.NotFound, FileNameWithPath(path = path, fileName = fileName))
is FileReadResult.Success -> {
call.response.header(
HttpHeaders.ContentDisposition,
ContentDisposition.Attachment.withParameter(ContentDisposition.Parameters.FileName, fileName)
.toString()
)
call.respondFile(result.file) {
headers {
if (downloadFileName.isNotBlank()) {
append(HttpHeaders.ContentDisposition, ContentDisposition.Attachment.withParameter(ContentDisposition.Parameters.FileName, downloadFileName).toString())
}
}
if (downloadFileName.isNotBlank()) {
call.response.header(
HttpHeaders.ContentDisposition,
ContentDisposition.Attachment.withParameter(ContentDisposition.Parameters.FileName, downloadFileName)
.toString()
)
} else {
call.response.header(
HttpHeaders.ContentDisposition,
ContentDisposition.Attachment.withParameter(ContentDisposition.Parameters.FileName, fileName)
.toString()
)
}
call.respondFile(result.file)
}
}
}
Expand Down

0 comments on commit 251fa54

Please sign in to comment.