This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-01
Channels
- # beginners (133)
- # boot (59)
- # cider (5)
- # cljs-dev (30)
- # cljsrn (23)
- # clojure (212)
- # clojure-austin (3)
- # clojure-brasil (1)
- # clojure-chicago (5)
- # clojure-italy (10)
- # clojure-russia (5)
- # clojure-serbia (1)
- # clojure-spec (34)
- # clojure-turkiye (2)
- # clojure-uk (132)
- # clojurescript (163)
- # clojutre (1)
- # cursive (5)
- # datomic (58)
- # emacs (42)
- # events (1)
- # graphql (26)
- # hoplon (16)
- # jobs (1)
- # lumo (27)
- # numerical-computing (3)
- # off-topic (127)
- # om (9)
- # onyx (24)
- # re-frame (20)
- # reagent (20)
- # ring-swagger (14)
- # sql (19)
- # unrepl (28)
- # untangled (3)
- # vim (8)
- # yada (17)
That's a final draft ready for public review - I would you really appreciate any bits of feedback - if anyone want to take a bit of time to run through the examples that would be really great
Yes I have. In Edge
I'll have a look now, @malcolmsparks
Reads well, seems very comprehensive. I haven't tried the examples (yet), clearly, but I will be referring back to this later in the week 😉
@malcolmsparks - I got my file upload working, but the start of the file that is written to the disk looks like this:
------WebKitFormBoundary7Svm17OQpKR5BTBx^M
Content-Disposition: form-data; name="upload-filename"^M
^M
gsod.csv^M
------WebKitFormBoundary7Svm17OQpKR5BTBx^M
Content-Disposition: form-data; name="rawdata-file-upload"; filename="GSOD_Data_PT_1992_to_2016_CDO8286807349283.csv"^M
Content-Type: text/csv^M
^M
Clearly I am getting something a bit wrong at the final hurdle... Not only is that ^^ happening, but I can't get the filename value from the form in the "ctx"
I've done a side-by-side between the example that you posted any my code and I admit I am defeated...
(I mean it looks as though it ought to work, so I can only assume that I am doing something dumb)
What content type are you using?
The form has the enctype="multipart/form-data" attribute and the yada resource looks like this:
(defn ingest-rawdata-upload
[]
(yada/resource
{:id :edge.resources/ingest-rawdata-upload
:description "Raw data Upload Resource"
:produces [{:media-type #{"text/html" "application/json"}
:charset "UTF-8"}]
:methods
{:get
{:swagger/tags ["default" "getters"]
:response
(fn [ctx]
(case (yada/content-type ctx)
"application/json" {:body "To upload POST to this endpoint instead with a body of appropriate JSON
metadata and a multi-part attachment of the data - see example"}
"text/html" (selmer/render-file
"ingest-rawdata-upload.html"
{:title "Cervest Ingest Platform - Raw Data Upload"
:ctx ctx})))}
:post
{:swagger/tags ["default" "posters"]
:parameters {:form {:upload-filename String}}
:consumes #{"application/x-www-form-urlencoded"
"multipart/form-data"
"application/octet-stream"}
:consumer (fn [ctx _ body-stream]
(println (get ctx :parameters)
)
(let [fname (get-in ctx [:parameters :form :upload-filename])
f (io/file (str (:external-files-path ingest-cfg) "/rawdata/gsod.csv"))]
(consume/save-to-file ctx body-stream f)))
:response (fn [ctx]
(case (yada/content-type ctx)
"application/json" {:body "Upload complete"}
"text/html" (selmer/render-file
"ingest-rawdata-upload-complete.html"
{:title "Cervest Ingest Platform - Raw Data Upload"
:ctx ctx})))}}}))
(I am pretty sure that the
:swagger/tags ["default" "posters"]
is bollocks too, been meaning to figure that out properlyI started out with just :application/octet-stream, but got loads of errors (HTTP 415 if memory serves)
Adding in "multipart/form-data" seemed to fix that, and I added "application/x-www-form-urlencoded" in the hope of getting the non-file form fields in the ctx
The idea was going to be that the user could supply a filename in a form field and then the "let" inside the consumer would go from this:
(let [fname (get-in ctx [:parameters :form :upload-filename])
f (io/file (str (:external-files-path ingest-cfg) "/rawdata/gsod.csv"))]
to this:
(let [fname (get-in ctx [:parameters :form :upload-filename])
f (io/file (str (:external-files-path ingest-cfg) fname))]