Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reagent/Re-frame example? #8

Open
rej156 opened this issue Jun 1, 2015 · 2 comments
Open

Reagent/Re-frame example? #8

rej156 opened this issue Jun 1, 2015 · 2 comments

Comments

@rej156
Copy link

rej156 commented Jun 1, 2015

What the title says, if plausible?

@GetContented
Copy link
Contributor

I use Reagent in my app's front end currently, and I'm just at the point where I'm going to integrate s3-beam into my app, so I can probably provide an example for that sometime soon, with any luck :)

@jdkealy
Copy link

jdkealy commented Apr 21, 2017

This is how i do it

REAGENT

(defn sign-and-upload [id file callback & [{:keys [file-name]}]]
  (let [params {:size (.-size file)
                :content/collection id
                :type (.-type file)
                :name (or file-name (.-name file))}]
    (POST "/signer" {:params params
                     :format :edn
                     :response-type :edn
                     :handler (fn [_params]
                                (let [params (assoc _params
                                                    "AWSAccessKeyId" util/access-key)
                                      params (doto
                                                 (reduce (fn [memo item]
                                                           (doto memo
                                                             (.append item (get params item)))) (js/FormData.) (keys params))
                                               (.append "file" file))
                                      xhr       (js/XMLHttpRequest.)]
                                  (-> xhr
                                      .-upload
                                      (.addEventListener "progress"
                                                         (fn [e]
                                                           (reset! loader [(.-loaded e)
                                                                           (.-total e)]))))
                                  (POST util/base-bucket {:params params
                                                          :api xhr
                                                          :response-format :raw
                                                          :handler (fn [e]
                                                                     (callback _params ))
                                                          :error-handler (fn [e]
                                                                           (.alert js/window "ERROR"))})))})))

clj

(POST "/signer" [] (fn [{:keys [edn-params user]}]
                       (let [fname (or (:name edn-params)
                                       "test")
                             newp {:metadata {:Content-Disposition "attachment"}
                                   :Content-Disposition "attachment"
                                   :file-name (str "uploads/"
                                                   (:db/id user)
                                                   "/"
                                                   (:content/collection edn-params)
                                                   "/"
                                                   (clojure.string/replace
                                                    fname
                                                    " "
                                                    "-"))
                                   :mime-type (:type edn-params)}]
                         (g/generate-json-response (sign-it newp)))))

(defn sign-it [newp]
  (dissoc
   (s3b/sign-upload
    newp
    {:bucket "secretbucket"
     :aws-key "itsasecret"
     :aws-zone "us-east-1"
     :aws-secret-key "secret-key"})
   :action
   :api_key))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants