anyone know a simple example posted online for downloading file stream? Like, generating a csv file for example. Or serving any file really.
@stvnmllr2 You want to serve a filestream, do I understand correctly?
well.. any stream. Or just a file if I have to.
so people can download their data from an app
web app
I'm serving images from a GridFS db in clojure like this, gimme a sec
(defn make-file-stream
"Takes an input stream `file` -- such as a MongoDBObject stream and streams it"
[file]
(rio/piped-input-stream
(fn [output-stream]
(.writeTo file output-stream))))
(defn download-file-by-id
"Downloads the requested file with `md5`"
[md5]
(let [mongo-file (first (db/get-file-md5 md5))
file-map (db/find-map-by-md5 md5)
content-type (-> file-map :contentType)
file-name (-> file-map :filename)]
(res/content-type {:status 200 :body (make-file-stream mongo-file)} content-type)))
;; then in my routes
(GET "/i/:md5" [md5] (download-file-by-id (first (string/split md5 #"\."))))
@alice. Closer than anything else I've found. Thanks! Will give it a go.
Keep in mind I only have to pipe the stream because I originate with an input stream