xeqi / peridot

a basic api for interacting with ring apps
145 stars 20 forks source link

Support several multipart files posted under the same key #50

Open apostolou opened 4 years ago

apostolou commented 4 years ago

Hello, thank you very much for this very useful library. I wanted to upload to my app under the same key several files. This is not possible currently with paridot. I did the changes to the multipart.clj file to be able to do so. Is this a feature that you'd like to add ? Do you want me to issue a pull request ? thx

PS: the code consists to replece the add-part multimethods by

(defmulti make-body-part type)

(defmethod make-body-part File [^File f]
  (FileBody. f (ContentType/create
                (mime-type/ext-mime-type (.getName f)))
             (.getName f)))

(defmethod make-body-part :default [v]
  (StringBody. (str v) (Charset/forName "UTF-8")))

(defmulti add-part
  (fn [_ _ v] (type v)))

(defmethod add-part clojure.lang.PersistentVector
  [^MultipartEntity m k ^clojure.lang.PersistentVector v]
  (doseq [b v]
    (add-part m k b)))

(defmethod add-part :default [^MultipartEntity m k v]
  (.addPart m (ensure-string k) (make-body-part v)))