Skip to content

Commit

Permalink
Added docs to multipart stores, made byte-array-store return a function
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Jul 17, 2011
1 parent 2b3f560 commit d81d573
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
14 changes: 10 additions & 4 deletions ring-core/src/ring/middleware/multipart_params/byte_array.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))
11 changes: 10 additions & 1 deletion ring-core/src/ring/middleware/multipart_params/temp_file.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")})]
Expand Down

0 comments on commit d81d573

Please sign in to comment.