metosin / compojure-api

Sweet web apis with Compojure & Swagger
http://metosin.github.io/compojure-api/doc/
Eclipse Public License 1.0
1.12k stars 149 forks source link

File download needs to disable json encoding of content body #379

Closed shark8me closed 6 years ago

shark8me commented 6 years ago

In the examples/thingie/src/examples/thingie.clj, downloading a file fails as the following code

   (GET "/file" []
        :summary "file download"
        :return File
        :produces ["image/png"]
        (-> (io/resource "screenshot.png")
            (io/input-stream)
            (ok)
            (header "Content-Type" "image/png"))))

tries to json-encode the BufferedInputStream by default.

I've changed the example to add a call to disable-response-encoding, and added a separate test for the same.

ikitommi commented 6 years ago

this is fixed in the latest Muuntaja & compojure-api 2.0.0 alpha - if a response has Content-Type header set, there will be no encoding, ever. Thanks for the PR, but closing this as resolved.