Skip to content

Instantly share code, notes, and snippets.

@weavejester
Forked from tgk/gist:618111
Created October 9, 2010 12:22
Show Gist options
  • Save weavejester/618137 to your computer and use it in GitHub Desktop.
Save weavejester/618137 to your computer and use it in GitHub Desktop.
(ns sandbox.file-upload
(:use ring.adapter.jetty
ring.util.response
ring.middleware.multipart-params
ring.middleware.stacktrace
hiccup.core
hiccup.form-helpers
compojure.core
clojure.pprint))
(def formula-site
(html5
[:head [:title "Upload formulas"]]
[:body
(for [action ["upload" "upload-foo" "dump-wrapped"]]
(list
[:h1 action]
(form-to {:enc-type "multipart/form-data"} [:post action]
(file-upload :file)
(submit-button "Upload"))))]]))
(defn upload-file [file]
(response (slurp (file :tempfile))))
(defn show-dump [req]
{:status 200
:headers {"Content-Type" "text/plain"}
:body (with-out-str (pprint req))})
(defroutes main-routes
(GET "/" [] formula-site)
(POST "/upload" [file]
(upload-file file))
(POST "/upload-foo" [file]
(upload-file file))
(POST "/dump-wrapped" request
(show-dump request))
(wrap! main-routes
:multipart-params
:stacktrace)
(defn start-server [port]
(future (run-jetty (var main-routes) {:port port})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment