using a custom :store with wrap-multipart-params in ring middle ware

57 views
Skip to first unread message

K Livingston

unread,
Apr 1, 2014, 6:14:22 PM4/1/14
to ring-c...@googlegroups.com
I'm having trouble using a custom :store with multipart-params.  I thought I did exactly what the documentation indicates, but I'm getting the default behavior.

 :store    - a function that stores a file upload. The function should
              expect a map with :filename, content-type and :stream keys,
              and its return value will be used as the value for the
              parameter in the multipart parameter map. The default storage
              function is the temp-file-store.


(mp/wrap-multipart-params 
   (POST "/upload-x" request (upload/upload-file request))
   {:store upload/logging-store})

My logging store function looks like this (it's just a dummy for now - eventually I want to handle the stream in a custom way) None of that IO happens.

(defn logging-store [{filename     :filename
                      content-type :content-type
                      stream       :stream
                      :as params}]
  (println "in logging store")
  (pprint filename)
  (pprint params)
  filename)

upload-file looks like this:

(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})))

The printing for the request and the params clearly show the multipart params in there and that they are being handled by the temp file store:

 :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"}},


cross post here (if you want stack overflow points):
Reply all
Reply to author
Forward
0 new messages