compojure-api icon indicating copy to clipboard operation
compojure-api copied to clipboard

File upload for clojure spec

Open NOBLES5E opened this issue 7 years ago • 5 comments

The current file upload wiki: https://github.com/metosin/compojure-api/wiki/Swagger-aware-File-uploads only works with schema. How to do this with clojure spec? Thanks.

NOBLES5E avatar Apr 14 '18 17:04 NOBLES5E

You can use any? can be used as a prediate.

ikitommi avatar Jun 15 '18 14:06 ikitommi

oh, the language :O

ikitommi avatar Jun 15 '18 14:06 ikitommi

Using any? won't have the coercion that makes it easy for me to access the file via something like upload/TempFileUpload?

NOBLES5E avatar Jun 15 '18 22:06 NOBLES5E

(s/def :file/filename string?)
(s/def :file/content-type string?)
(s/def :file/size integer?)
(s/def :file/tempfile #(instance? java.io.File %))
(s/def ::file (st/spec {:spec (s/keys :req-un [:file/filename :file/content-type :file/size]
                                      :opt-un [:file/tempfile])
                        :json-schema/type "file"}))

Deraen avatar Jun 19 '18 13:06 Deraen

nice! ~s/:file\//::/g, this could be under compojure.api.specs?

ikitommi avatar Jun 19 '18 14:06 ikitommi