Permalink
Browse files

Added docs to multipart stores, made byte-array-store return a function

  • Loading branch information...
1 parent 2b3f560 commit d81d57358c62357e8dfc2e54660c811a3983737b @weavejester weavejester committed Jul 17, 2011
View
14 ring-core/src/ring/middleware/multipart_params/byte_array.clj
@@ -2,7 +2,13 @@
(:import org.apache.commons.io.IOUtils))
(defn byte-array-store
- "Stores multipart file parameters as an array of bytes."
- [item]
- (-> (select-keys item [:filename :content-type])
- (assoc :bytes (IOUtils/toByteArray (:stream item)))))
+ "Returns a function that stores multipart file parameters as an array of
+ bytes. The multipart parameters will be stored as maps with the following
+ keys:
+ :filename - the name of the uploaded file
+ :content-type - the content type of the uploaded file
+ :bytes - an array of bytes containing the uploaded content"
+ []
+ (fn [item]
+ (-> (select-keys item [:filename :content-type])
+ (assoc :bytes (IOUtils/toByteArray (:stream item))))))
View
11 ring-core/src/ring/middleware/multipart_params/temp_file.clj
@@ -27,7 +27,16 @@
temp-file))
(defn temp-file-store
- "Stores multipart file parameters as a temporary file."
+ "Returns a function that stores multipart file parameters as temporary files.
+ Accepts the following options:
+ :expires-in - delete temporary files older than this many seconds
+ (defaults to 3600 - 1 hour)
+ The multipart parameters will be stored as maps with the following keys:
+ :filename - the name of the uploaded file
+ :content-type - the content type of the upload file
+ :tempfile - a File object that points to the temporary file containing
+ the uploaded data.
+ :size - the size in bytes of the uploaded data"
([] (temp-file-store {:expires-in 3600}))
([{:keys [expires-in]}]
(fn [item]
View
3 ring-core/test/ring/middleware/multipart_params/byte_array_test.clj
@@ -4,7 +4,8 @@
ring.middleware.multipart-params.byte-array))
(deftest test-byte-array-store
- (let [result (byte-array-store
+ (let [store (byte-array-store)
+ result (store
{:filename "foo.txt"
:content-type "text/plain"
:stream (string-input-stream "foo")})]

0 comments on commit d81d573

Please sign in to comment.