Created
October 9, 2010 11:31
-
-
Save tgk/618111 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 | |
(html | |
[:html | |
[:head [:title "Upload formulas"]] | |
[:body | |
(for [action ["upload" "upload-foo" "dump-wrapped"]] | |
(html | |
[:h1 action] | |
[:form {:method "POST" | |
:action action | |
:enctype "multipart/form-data"} | |
(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" {params :params} (upload-file (params "file"))) | |
wrap-multipart-params | |
wrap-stacktrace) | |
(-> (POST "/upload-foo" {params :params} (upload-file (params "file"))) | |
wrap-multipart-params | |
wrap-stacktrace) | |
(-> (POST "/dump-wrapped" req (show-dump req)) | |
wrap-multipart-params)) | |
(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