ring icon indicating copy to clipboard operation
ring copied to clipboard

Add :field to :store option in ring.middleware.multipart-params

Open meowcakes opened this issue 10 years ago • 2 comments

It would be nice to also have the field name passed to the :store function, like so:

(defn- parse-file-item
  "Parse a FileItemStream into a key-value pair. If the request is a file the
  supplied store function is used to save it."
  [^FileItemStream item store encoding]
  [(.getFieldName item)
   (if (.isFormField item)
     (Streams/asString (.openStream item) encoding)
     (store {:filename     (.getName item)
             :field        (.getFieldName item)
             :content-type (.getContentType item)
             :stream       (.openStream item)}))])

This way different logic can be applied depending on the field.

Thanks

meowcakes avatar Aug 21 '15 01:08 meowcakes

To what end? Can you describe your use-case?

weavejester avatar Aug 21 '15 01:08 weavejester

So I have two (very large) files being uploaded with field names "foo" and "bar". I want to, while the upload is in progress, analyse the contents of the files while storing them somewhere. This way I can give the user instant feedback of the analysis after the files are uploaded, rather than subsequently analysing them from wherever they're stored after the upload is finished, which would incur a significant delay.

But, "foo" and "bar" need to be analysed in a different way, and the only way to figure out which analysis to perform is to have the field name.

meowcakes avatar Aug 21 '15 01:08 meowcakes