Created
November 5, 2012 22:41
-
-
Save duelinmarkers/4020886 to your computer and use it in GitHub Desktop.
Handling file upload in a ring app
This file contains 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
(ring.adapter.jetty/run-jetty | |
(ring.middleware.params/wrap-params | |
(ring.middleware.multipart-params/wrap-multipart-params | |
(fn [request] | |
(if (= :get (:request-method request)) | |
(render-html-form-with-file-field-called "my-file") | |
(let [file (get-in req [:params "my-file" :tempfile])] | |
; file is a java.io.File | |
(with-open [reader (clojure.java.io/reader file)] | |
; reader is a--You guessed it!--java.io.Reader | |
(render-result | |
(clojure.data.csv/read-csv reader)))))))) | |
{:port 8000}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used in http://elhumidor.blogspot.com/2012/11/how-to-handle-file-uploads-from-clojure.html