2016-10-12 30 views
0

我遵循书web development with clojure, 2nd edition的示例代码,我有一个与谷歌关闭文件上传的问题。cljs + luminus框架:文件上传与谷歌关闭

我测试用扬鞭文件上传,它响应了我200 OK,我认为错误是从上传文件!函数(见下文)。

但我抬头看看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]]) 
+0

这是我的错误....我发现了它,我应该输入:form.ui.form,而不是:div.ui.form 。对此问题的回答.. – g1eny0ung

+0

您可以回答自己的问题并将其标记为已解决:http://stackoverflow.com/help/self-answer – n2o

+0

谢谢您的提醒@n2o,我会回答^ _ ^,起初我认为这只是一个写错误,并不需要回答。但是你是对的,我应该把它标记为已解决。 – g1eny0ung

回答

0

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

,如果你在代码的兴趣,你可以查看这个网址: upload image code