|
141 | 141 | (response/bad-request (.getMessage e))) |
142 | 142 |
|
143 | 143 | (defn wrap-multipart-params |
144 | | - "Middleware to parse multipart parameters from a request. Adds the |
145 | | - following keys to the request map: |
| 144 | + "Middleware to parse multipart parameters from a request. Adds the following |
| 145 | + keys to the request map: |
146 | 146 |
|
147 | 147 | :multipart-params - a map of multipart parameters |
148 | 148 | :params - a merged map of all types of parameter |
149 | 149 |
|
150 | | - The following options are accepted |
| 150 | + The following options are accepted: |
151 | 151 |
|
152 | 152 | :encoding |
153 | | - - Character encoding to use for multipart parsing. |
154 | | - Overrides the encoding specified in the request. If not |
155 | | - specified, uses the encoding specified in a part named |
156 | | - \"_charset_\", or the content type for each part, or |
157 | | - request character encoding if the part has no encoding, |
158 | | - or \"UTF-8\" if no request character encoding is set. |
| 153 | + - Character encoding to use for multipart parsing. Overrides the encoding |
| 154 | + specified in the request. If not specified,uses the encoding specified in a |
| 155 | + part named \"_charset_\", or the content type for each part, or request |
| 156 | + character encoding if the part has no encoding, or \"UTF-8\" if no request |
| 157 | + character encoding is set. |
159 | 158 |
|
160 | 159 | :fallback-encoding |
161 | | - - Specifies the character encoding used in parsing if a |
162 | | - part of the request does not specify encoding in its |
163 | | - content type or no part named \"_charset_\" is present. |
164 | | - Has no effect if :encoding is also set. |
| 160 | + - Specifies the character encoding used in parsing if a part of the request |
| 161 | + does not specify encoding in its content type or no part named \"_charset_\" |
| 162 | + is present. Has no effect if :encoding is also set. |
165 | 163 |
|
166 | 164 | :store |
167 | | - - A function that stores a file upload. The function |
168 | | - should expect a map with :filename, :content-type and |
169 | | - :stream keys, and its return value will be used as the |
170 | | - value for the parameter in the multipart parameter map. |
171 | | - The default storage function is the temp-file-store. |
| 165 | + - A function that stores a file upload. The function should expect a map with |
| 166 | + :filename, :content-type and :stream keys, and its return value will be used |
| 167 | + as the value for the parameter in the multipart parameter map. The default |
| 168 | + storage function is the temp-file-store. |
172 | 169 |
|
173 | 170 | :progress-fn |
174 | | - - A function that gets called during uploads. The |
175 | | - function should expect four parameters: request, |
176 | | - bytes-read, content-length, and item-count. |
| 171 | + - A function that gets called during uploads. The function should expect four |
| 172 | + parameters: request, bytes-read, content-length, and item-count. |
177 | 173 |
|
178 | 174 | :invalid-filename-handler |
179 | | - - A function that gets called when the file being uploaded |
180 | | - has an invalid name. The function should expect two |
181 | | - parameters: request and an exception of type |
| 175 | + - A function that gets called when the file being uploaded has an invalid name. |
| 176 | + The function should expect two parameters: request and an exception of type |
182 | 177 | InvalidFileNameException. It should return a ring response." |
183 | 178 | ([handler] |
184 | 179 | (wrap-multipart-params handler {})) |
185 | 180 | ([handler options] |
186 | | - (fn |
187 | | - ([request] |
188 | | - (let [req-or-ex (try |
189 | | - (multipart-params-request request options) |
190 | | - (catch Exception ex ex)) |
191 | | - invalid-filename-handler |
192 | | - (:invalid-filename-handler options default-invalid-filename-handler)] |
193 | | - (if (instance? Throwable req-or-ex) |
194 | | - (invalid-filename-handler request req-or-ex) |
195 | | - (handler req-or-ex)))) |
196 | | - ([request respond raise] |
197 | | - (let [req-or-ex (try |
198 | | - (multipart-params-request request options) |
199 | | - (catch Exception ex ex)) |
200 | | - invalid-filename-handler |
201 | | - (:invalid-filename-handler options default-invalid-filename-handler)] |
202 | | - (if (instance? Throwable req-or-ex) |
203 | | - (respond (invalid-filename-handler request req-or-ex)) |
204 | | - (handler req-or-ex respond raise))))))) |
| 181 | + (let [invalid-filename-handler |
| 182 | + (:invalid-filename-handler options default-invalid-filename-handler)] |
| 183 | + (fn ([request] |
| 184 | + (let [req-or-ex (try |
| 185 | + (multipart-params-request request options) |
| 186 | + (catch Exception ex ex))] |
| 187 | + (if (instance? Throwable req-or-ex) |
| 188 | + (invalid-filename-handler request req-or-ex) |
| 189 | + (handler req-or-ex)))) |
| 190 | + ([request respond raise] |
| 191 | + (let [req-or-ex (try |
| 192 | + (multipart-params-request request options) |
| 193 | + (catch Exception ex ex))] |
| 194 | + (if (instance? Throwable req-or-ex) |
| 195 | + (respond (invalid-filename-handler request req-or-ex)) |
| 196 | + (handler req-or-ex respond raise)))))))) |
0 commit comments