Skip to content

Instantly share code, notes, and snippets.

@duelinmarkers
Created November 5, 2012 22:41
Show Gist options
  • Save duelinmarkers/4020886 to your computer and use it in GitHub Desktop.
Save duelinmarkers/4020886 to your computer and use it in GitHub Desktop.
Handling file upload in a ring app
(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