ring-clojure / ring

Clojure HTTP server abstraction
MIT License
3.77k stars 520 forks source link

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

Open meowcakes opened 9 years ago

meowcakes commented 9 years ago

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

weavejester commented 9 years ago

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

meowcakes commented 9 years ago

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.