Fork me on GitHub
#reitit
<
2022-02-14
>
ikitommi16:02:48

reitit + malli-lite for the curious: • [metosin/reitit "0.5.16-SNAPSHOT"]https://cljdoc.org/d/metosin/reitit/0.5.16-SNAPSHOT/doc/coercion/malli#lite-syntax

👍 4
malli 3
aeskilson18:02:08

I’m curious how I can coerce file uploads to byte streams. I have a route defined with a spec-based type that resolves to reitit.ring.middleware.multipart/bytes-part. The generated Swagger UI allows me to upload the data, but the request ultimately fails with a spec error, I suppose that the file hasn’t been coerced to bytes? I can see the “Content-Type” of the request seems to be things like “text/csv” depending on what I send. If I choose temp-file-part, the requests succeed, and I can see a temp file has been written, which I’d be able to move. I’d prefer byte-streams though. Does this problem seem like it’s on Swagger UI’s side? That it isn’t reading the swagger.json correctly? I can see the swagger.json is saying the content-type should be bytes:

{"/my_route":{"post":{"responses":{"default":{"description":""}},"consumes":["multipart/form-data"],"parameters":[{"in":"formData","name":"file","description":"","type":"file","required":["filename","content-type","bytes"],"properties":{"filename":{"type":"string"},"content-type":{"type":"string"},"bytes":{"type":"string","format":"byte"}} ...}
Perhaps I haven’t configured my coercer’s correctly? I’m using Pedestal, and I do have the (multipart/multipart-interceptor) interceptor generator function called at the bottom of my interceptor chain’s declaration.

Hukka07:02:26

Have you added the multipart middleware with the byte-array store?

Hukka07:02:26

Not sure if the the pedestal interceptor does something differently, but the plain reitit multipart middleware will set up with temp files by default