This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-17
Channels
- # aws (10)
- # beginners (64)
- # boot (3)
- # cider (20)
- # cljs-dev (32)
- # cljsrn (6)
- # clojure (126)
- # clojure-dusseldorf (3)
- # clojure-finland (1)
- # clojure-greece (1)
- # clojure-italy (7)
- # clojure-poland (3)
- # clojure-spec (46)
- # clojure-uk (100)
- # clojurescript (37)
- # cursive (11)
- # datomic (6)
- # defnpodcast (2)
- # emacs (1)
- # events (3)
- # figwheel (2)
- # fulcro (20)
- # immutant (2)
- # jobs (1)
- # jobs-discuss (9)
- # keechma (3)
- # lein-figwheel (1)
- # luminus (2)
- # lumo (3)
- # mount (2)
- # off-topic (19)
- # om (3)
- # om-next (2)
- # onyx (20)
- # other-languages (55)
- # parinfer (11)
- # pedestal (8)
- # portkey (3)
- # protorepl (3)
- # re-frame (22)
- # ring (9)
- # rum (1)
- # shadow-cljs (82)
- # spacemacs (28)
- # sql (15)
- # test-check (15)
- # testing (2)
- # tools-deps (102)
- # vim (26)
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?
(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 #"\."))))