Created
January 31, 2012 18:32
-
-
Save fracek/1712066 to your computer and use it in GitHub Desktop.
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
(defpage "/" [] | |
(common/layout | |
(form-to {:enctype "multipart/form-data"} | |
[:post "/upload"] | |
(label :file "File to upload:") | |
(file-upload :file) | |
[:br] | |
(submit-button "Upload")))) |
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
; 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"))) |
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
(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