[英]cljs + luminus framework:file upload with google closure
我遵循了Clojure(第二版)的書本網絡開發示例代碼,並且使用Google Closure上傳文件時遇到問題。
我用Swagger測試了文件上傳,它回復了200 ok ,我認為錯誤是來自上傳文件! 功能(見下文)
但是我查了閉包api doc ,看來我使用了正確的函數。
所以我遇到了麻煩,我不知道為什么它不起作用...
我需要別人的幫助,這是我的代碼(我將ui-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: 上傳圖像代碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.