Skip to content

Instantly share code, notes, and snippets.

@fracek
Created January 31, 2012 18:32
Show Gist options
  • Save fracek/1712066 to your computer and use it in GitHub Desktop.
Save fracek/1712066 to your computer and use it in GitHub Desktop.
(defpage "/" []
(common/layout
(form-to {:enctype "multipart/form-data"}
[:post "/upload"]
(label :file "File to upload:")
(file-upload :file)
[:br]
(submit-button "Upload"))))
; Show this page in case of success
(defpage "/success" []
(common/layout
[:h2 "File uploaded!"]))
; Show this page in case of failure
(defpage "/fail" []
(common/layout
[:h2 "Something went wrong"]))
;; S3 keys - replace with your keys
(def *server-spec* {:secret-key "SECRET KEY" :access-key "ACCESS KEY"})
(defpage [:post "/upload"] {:keys [file]}
(if (= "0" (:size file))
(do
;; Upload the file to the "s3-tut" bucket
(binding [s3/*s3* (s3/service *server-spec*)]
(s3/put! "s3-tut" (:tempfile file)))
(resp/redirect "/success"))
(resp/redirect "/fail")))
(ns file-uploadr.views.upload
(:require [file-uploadr.views.common :as common]
[noir.content.pages :as pages]
[noir.response :as resp]
[noir.util.s3 :as s3])
(:use noir.core
hiccup.core
hiccup.page-helpers
hiccup.form-helpers))
(defpage "/" []
(common/layout
[:p "Welcome to file-uploadr"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment