Fork me on GitHub

Hey there, I'm having some trouble regarding file upload using the ring.swagger.upload middleware. I'm trying to have a post request which takes a file and some form data, like:

(POST "/my-request" [] :return s/Str :form-params [name :- s/Str] :multipart-params [file :- upload/TempFileUpload] :middleware [upload/wrap-multipart-params] (ok (str (slurp (:tempfile file) " " name)))) 
but when testing the request I get an error message:
when using body-params (or simply body) instead of form-params I'll get the following validaiton error:
{"errors": "(not (map? nil))"} 
I'm not sure if I'm missing something here or there is a problem in the ring.swagger.upload middleware, maybe someone of you could help? thanks


When you send data with a file, all fields will be found on mulipart-params


When you send a file the content-type of request will be multipart/form-data and all data is found in ring request map under multipart-params key. form-params corresponds to application/x-www-form-urlencoded request data and body-params to JSON/EDN/Transit/etc.


Oh okay thanks! So smth like

:multipart-params [file :- upload/TempFileUpload, name :- s/Str] 
will work? thanks


Yes, that should work


thank you very much!


Your browsers developer tools should allow checking the contents and headers of the requests