Skip to content

Swagger aware File uploads

Juho Teperi edited this page Dec 18, 2015 · 4 revisions

Mostly provided by Ring-Swagger. Restructuring :multipart-params pushes also multipart/form-data as the only available consumption.

;; versions before 0.23.0
(require '[compojure.api.upload :as upload])

;; versions 0.23.0+
(require '[ring.swagger.upload :as upload])

(POST* 
  "/upload" []
  :multipart-params [file :- upload/TempFileUpload]
  :middlewares [upload/wrap-multipart-params]
  (ok (dissoc file :tempfile)))

Route-specific middlewares

Key :middlewares takes a vector of middlewares to be applied to the route. Note that the middlewares don't see any restructured bindings from within the route body. They are executed inside the route so you can safely edit request etc. and the changes won't leak to other routes in the same context.

 (DELETE* "/user/:id" []
   :middlewares [audit-support (for-roles :admin)]
   (ok {:name "Pertti"}))
Clone this wiki locally