|
86 | 86 |
|
87 | 87 | (def ^:private default-store (delay (tf/temp-file-store)))
|
88 | 88 |
|
89 |
| -(defn- parse-multipart-params |
90 |
| - [request {:keys [encoding fallback-encoding store max-file-count] |
91 |
| - :as options}] |
92 |
| - (let [store (or store @default-store) |
93 |
| - fallback-encoding (or encoding |
94 |
| - fallback-encoding |
95 |
| - (req/character-encoding request) |
96 |
| - "UTF-8")] |
97 |
| - (->> (request-context request fallback-encoding) |
98 |
| - (file-item-iterable (file-upload request options)) |
99 |
| - (sequence |
100 |
| - (map-indexed (fn [i item] |
101 |
| - (if (and max-file-count (>= i max-file-count)) |
102 |
| - (throw (ex-info "Max file count exceeded" |
103 |
| - {:max-file-count max-file-count})) |
104 |
| - (parse-file-item item store))))) |
105 |
| - (build-param-map encoding fallback-encoding)))) |
| 89 | +(defn parse-multipart-params |
| 90 | + "Parse a multipart request map and return a map of parameters. For a list of |
| 91 | + available options, see: wrap-multipart-params." |
| 92 | + {:added "1.14"} |
| 93 | + ([request] |
| 94 | + (parse-multipart-params request {})) |
| 95 | + ([request options] |
| 96 | + (when (multipart-form? request) |
| 97 | + (let [store (or (:store options) @default-store) |
| 98 | + max-file-count (:max-file-count options) |
| 99 | + encoding (:encoding options) |
| 100 | + fallback-encoding (or encoding |
| 101 | + (:fallback-encoding options) |
| 102 | + (req/character-encoding request) |
| 103 | + "UTF-8")] |
| 104 | + (->> (request-context request fallback-encoding) |
| 105 | + (file-item-iterable (file-upload request options)) |
| 106 | + (sequence |
| 107 | + (map-indexed (fn [i item] |
| 108 | + (if (and max-file-count (>= i max-file-count)) |
| 109 | + (throw (ex-info "Max file count exceeded" |
| 110 | + {:max-file-count max-file-count})) |
| 111 | + (parse-file-item item store))))) |
| 112 | + (build-param-map encoding fallback-encoding)))))) |
106 | 113 |
|
107 | 114 | (defn multipart-params-request
|
108 | 115 | "Adds :multipart-params and :params keys to request.
|
|
111 | 118 | ([request]
|
112 | 119 | (multipart-params-request request {}))
|
113 | 120 | ([request options]
|
114 |
| - (let [params (if (multipart-form? request) |
115 |
| - (parse-multipart-params request options) |
116 |
| - {})] |
| 121 | + (let [params (or (parse-multipart-params request options) {})] |
117 | 122 | (merge-with merge request
|
118 | 123 | {:multipart-params params}
|
119 | 124 | {:params params}))))
|
|
0 commit comments