this fn donwloads the file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn make-file-stream | |
"Takes an input stream and streams it" | |
[file] | |
(io/piped-input-stream | |
(fn [output-stream] | |
(.writeTo file output-stream)))) | |
(defn download-file-by-path | |
"Downloads the requested file, ie. streams it to the client" | |
[file-path file-name content-type] | |
(let [content-length (.length (cio/file file-path)) | |
resp (-> file-path | |
make-file-stream | |
r/response | |
(#(r/header % "Content-Length" content-length)) | |
(#(r/header % "Content-Disposition" ; to get the right default file-name | |
(str "attachment; filename=\"" file-name "\""))) | |
(#(r/header % "Content-Type" content-type)))] | |
resp)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment