cljs + luminus框架:谷歌关闭文件上传

时间:2016-10-12 09:01:32

标签: clojure clojurescript google-closure-compiler luminus

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

我使用Swagger测试文件上传,它响应我 200 ok ,我认为错误来自上传文件!功能。(见下文)。< / p>

但我抬头看closure api doc,似乎我使用了正确的功能。

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

我需要有人帮忙。这是我的代码(我对ui组件使用semantic-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]])

1 个答案:

答案 0 :(得分:0)

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

如果您对代码感兴趣,可以查看以下网址: upload image code