Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure 在ring中间件中使用自定义:store和wrap多部分参数_Clojure_Compojure_Ring - Fatal编程技术网

Clojure 在ring中间件中使用自定义:store和wrap多部分参数

Clojure 在ring中间件中使用自定义:store和wrap多部分参数,clojure,compojure,ring,Clojure,Compojure,Ring,我试图为包装多部分参数使用一个自定义的:store选项,而我显然得到了默认的存储。我的自定义函数甚至没有被调用 (mp/wrap-multipart-params (POST "/upload-x" request (upload/upload-file request)) {:store upload/logging-store}) 我的logging store函数看起来是这样的(目前它只是一个伪函数——最终我希望以自定义方式处理流),这些IO都不会发生 (defn logg

我试图为
包装多部分参数
使用一个自定义的
:store
选项,而我显然得到了默认的存储。我的自定义函数甚至没有被调用

(mp/wrap-multipart-params 
   (POST "/upload-x" request (upload/upload-file request))
   {:store upload/logging-store})
我的logging store函数看起来是这样的(目前它只是一个伪函数——最终我希望以自定义方式处理流),这些IO都不会发生

(defn logging-store [{filename     :filename
                      content-type :content-type
                      stream       :stream
                      :as params}]
  (println "in logging store")
  (pprint filename)
  (pprint params)
  filename)
上载文件如下所示:

(defn upload-file [{params :params
                    session :session :as request}]
  (let [user-id (:user-id session)
        files (get params "files")]
    (pprint request)
    (pprint params)
    (response/response
     {:status    :success})))
请求和参数的打印清楚地显示了其中的多部分参数,并且它们正由临时文件存储区处理:

 :multipart-params
 {"files"
  {:size 1674,
   :tempfile
   #<File /var/folders/rx/9ntjyyvs35qbmcbp6rhfmj200000gn/T/ring-multipart-3853352501927893381.tmp>,
   :content-type "application/octet-stream",
   :filename "blog-test.clj"}},

compojure.handler/site
函数包含
wrap multipart params
中间件,因此您在不知不觉中应用了多部分中间件两次:首先使用默认值,然后使用自定义选项。因为具有默认选项的多部分中间件是首先应用的,所以优先考虑。

Arg,我甚至去寻找类似的东西。。。但我没想到要去那里看看。看起来也有传递多部分参数的参数(假设它们对整个站点都是相同的)。为什么要先应用默认参数,这看起来有点像是由内而外的?
(defroutes file-list-routes
  (GET "/simple-upload" request (upload/simple-upload-file request))
  (mp/wrap-multipart-params 
   (POST "/upload-x"        request (upload/upload-file    request))
   {:store upload/logging-store})
  )


(defroutes scratch-app
  (context "/files" request file-list-routes)
  (route/resources "/")
  (route/not-found "Page not found"))

(def my-app
  (handler/site
   (ring.middleware.json/wrap-json-response
    (ring.middleware.json/wrap-json-params
     (ring.middleware.stacktrace/wrap-stacktrace
      (ring.middleware.session/wrap-session 
       scratch-app
       {:store (ring.middleware.session.memory/memory-store all-the-sessions)
        :cookie-attrs {:max-age 3600 ;in s 3600s = 1h
                       }}))))))

(ring.util.servlet/defservice my-app)