0

我遵循使用 clojure 进行图书 Web 开发的示例代码,第 2 版,我在使用 google 关闭时上传文件时遇到问题。

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

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

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

我需要有人帮助。这是我的代码(我对 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]])
4

1 回答 1

0

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

对代码感兴趣的可以查看这个网址: 上传图片代码

于 2016-10-13T14:44:31.340 回答