cljs + luminus framework:file 上传 google 闭包

cljs + luminus framework:file upload with google closure

我按照书 web development with clojure, 2nd edition 中的示例代码进行操作,但在使用 google 关闭文件上传时遇到问题。

我用 Swagger 测试文件上传,它回复我 200 ok,我认为错误来自 upload-file!功能。(见下文)。

不过我查了一下closure api doc,好像我用的是正确的函数。

所以我遇到了麻烦,我不知道为什么它不起作用...

我需要有人 help.Here 是我的代码(我对 ui 组件使用语义-ui):

(defn upload-file! [upload-form-id status]
 (reset! status nil)
 (let [io (IframeIo.)]
  (gev/listen
   io goog.net.EventType.SUCCESS
   #(reset! status [c/success-message "file uploaded successfully"]))
  (gev/listen
   io goog.net.EventType.ERROR
   #(reset! status [c/warning-message "failed to upload the file"]))
  (.setErrorChecker io #(= "error" (.getResponseText io)))
  (.sendFromForm io (.getElementById js/document upload-form-id) "/upload")))

(defn upload-form []
  (let [status (atom nil)
        form-id "upload-form"]
  (fn []
    [c/modal
     [:div "Upload File"]
     [:div
      (when @status @status)
      [:div.ui.form
       {:id form-id
        :enc-type "multipart/form-data"
        :method "POST"}
       [:label {:for "file"} "select an image for upload"]
       [:input {:id "file"
                :name "file"
                :type "file"}]]]
     [:div
      [:button.ui.primary.button
       {:on-click #(upload-file! form-id status)}
       "upload"]
      [:button.ui.red.button
       {:on-click #(do
                     (.modal (js/$ ".ui.modal") "hide")
                     (reset! status nil))}
       "Cancel"]]
     "upload"])))

组件:

(defn modal [header content footer id]
 [:div.ui.modal
  {:id id}
  [:div.header header]
  [:div.content content]
  [:div.actions footer]])


(defn success-message [content]
 [:div.ui.green.message
  [:div.header content]])

所以我解决了我的问题,我应该输入 [:form:ui.form] 而不是 [:div.ui.form]

如果你对代码感兴趣,可以查看这个URL: upload image code