Fork me on GitHub

hey folks --- does anyone wanna explain to a web-stuff noob how to actually set headers in a luminus application to have a route give the browser headers appropriate for downloading a json file? I'm using a pretty much straight luminus + mongodb template app with whatever middleware comes in by default, and I've got a route defined as follows: (GET "/download-data" [] (db/dump-dockets)) where db/dump-dockets is just a call to monger's find-maps function to deliver the whole database as a vector of maps. And this works almost perfectly: it returns a well-formated json string containing the contents of the database as expected. Which is 90% of what I want. The 10% shortfall is that it displays it in the browser window instead of prompting the user to download as a file. My minimal knowledge of http stuff suggests to me that that means I need to set a header somewhere, but I'm terrified of messing with the middleware and breaking everything (it's taken a long time to get everything else working...)


@gowder: I think you'll need to add the header Content-Disposition: attachment


Your usual ring response would look like


{:status 200
   :headers {"Content-Type" "application/json"}
   :body {:text "Hello World"}}


so assuming you have it in a variable res


(-> res
   (assoc [:headers "Content-Disposition"] "attachment"))


thanks @jethroksy ! let's see if I can just slap that on top of a compojure route and have it work by magic 🙂


well, because I really don't understand the magic going on behind the scenes between compojure and ring, so I just used to handle matters myself, but seems to work:

(defn downloadable-json-string [m]
  {:status 200 :headers {"Content-Type" "application/json" "Content-Disposition" "attachment"} :body (write-str m)})

(defroutes home-routes
;; ...
  (GET "/data-to-file" [] (downloadable-json-string (db/dump-dockets)))


Has anyone tried to deploy a Luminus web app to Amazon Web Services (Elastic Beanstalk)? I'm stuck with migrations. The web app currently throws me an error about tables that do not exist. I've tried with following snippet in .ebextensions:

        command: java -jar target/uberjar/myproject.jar migrate
        leader_only: true
but I know it's a shot in the dark. I have no idea about which command could work, and logs don't give any clues.