This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-07-15
Channels
- # aleph (8)
- # architecture (8)
- # babashka (26)
- # beginners (20)
- # calva (14)
- # clojure (6)
- # clojure-dev (28)
- # clojure-europe (39)
- # clojure-france (2)
- # clojure-korea (3)
- # clojure-losangeles (2)
- # clojure-nl (2)
- # clojure-norway (9)
- # clojure-uk (7)
- # clojurescript (10)
- # clr (1)
- # cursive (22)
- # data-science (19)
- # datomic (16)
- # jobs-discuss (2)
- # leiningen (3)
- # off-topic (10)
- # polylith (4)
- # reitit (2)
- # releases (1)
- # ring (10)
- # uncomplicate (1)
- # xtdb (6)
So, I have a java.io.BufferedInputStream
which is returned from an S3 request for an image. I'd like to return that from my ring server. I tried something like returning {:body (:Body s3-res)}
, which doesn't seem to work. The browser ends up returning an ASCII file with the contents #object[java.io.BufferedInputStream 0x65b906f0 "
. What's the proper way of doing this?
I was looking at the docs and I found ring.core.protocols/StreamableResponseBody
, If I do (satisfies? ring.core.protocols/StreamableResponseBody (:Body s3-res))
it returns true :thinking_face:
This is more or less the code that I wrote
(let [s3-res (cogs-aws/invoke s3 {:op :GetObject
:request {:Bucket bucket
:Key s3-key}})]
(-> (ring.util.response/response (:Body s3-res))
(g/partial-content)
(rerus/header "Content-Range" (:ContentRange s3-res))
(rerus/header "Content-Type" (:ContentType s3-res))
(rerus/header "Content-Length" (:ContentLength s3-res))
(rerus/header "Accept-Ranges" (:AcceptRanges s3-res))
(rerus/header "Content-Disposition" "attachment")))
My guess is you have a middlewares that is pr-str or similar (maybe json encoding?) the stream so it becomes that not useful string before it reaches the code that actually handles it as a StreamableResponseBody