Fork me on GitHub
#yada
<
2021-02-24
>
eelke08:02:23

Hello, I have a question. I am trying to set up a server that can receive and process multipart messages. My attempt is with aleph with yada resources. But I have difficulties in processing the manifold.stream in the response. Do you have some tips and tricks? I am trying to use parse-multipart in this way:

(yada/listener
    ["/some-route"
     (yada/resource {:methods
                     {:post {:consumes "multipart/form-data"
                             :produces "application/json"
                             :response (fn [ctx]
                                         (let [boundary (last (clojure.string/split (get-in ctx [:request :headers "content-type"]) #"="))]
                                           (try   (->> (get-in ctx [:request :body])
                                                       (yada.multipart/parse-multipart boundary 10000 1000)
                                                       (manifold.stream/transform (xf-bytes->content))
                                                       manifold.stream/stream->seq)
                                                  (catch Exception e
                                                    (println (.getMessage e)))))
                                         (clojure.data.json/write-str {:success true}))}}})]
    {:port        1234
     :raw-stream? true
     :executor    (flow/utilization-executor 0.9 64)})