Fork me on GitHub
#ring-swagger
<
2016-02-16
>
amp21:02:47

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:
{"errors":{"name":"missing-required-key"}}
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

juhoteperi21:02:15

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

juhoteperi21:02:19

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.

amp21:02:50

Oh okay thanks! So smth like

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

juhoteperi21:02:03

Yes, that should work

amp21:02:10

thank you very much!

juhoteperi21:02:41

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