-
-
Save weavejester/618137 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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