How to extract the form data from a request in liberator?

11 views
Skip to first unread message

Prikshet Sharma

unread,
Mar 5, 2020, 5:14:35 AM3/5/20
to Liberator
I have the following client-side request:

```
(let [form-data (doto
                       (js/FormData.)
                     (.append "filename" file))]
     (ajax-request
      {:uri "/some/uri"
       :method :post
       :body form-data
       :format (raw-request-format)
       :response-format (raw-response-format)})
     )
```

And on the server (with liberator):

```
(defresource some-resource [_]
  :allowed-methods [:get :post]
  :available-media-types ["application/json"]
  :exists? (fn [ctx]
             (prn "form-data " (-> ctx :request :body slurp)) ;prints
             (prn "form-data " (-> ctx :request :body slurp cheshire/decode)) ;doesn't print
             ))

```

At the server, I do get the print of the form-data like so:

```
"form-data " "------WebKitFormBoundaryI9CA2zKhFT0Stmx7\r\nContent-Disposition: form-data; name=\"new-name\"\r\n\r\n{:uploaded-file #object[File [object File]], :name \"somename\", :another \"1234\"}\r\n------WebKitFormBoundaryI9CA2zKhFT0Stmx7--\r\n"
```
But the next prn doesn't print anything where my goal is to extract the :uploaded-file. What am I doing wrong?

Philipp Meier

unread,
Mar 5, 2020, 5:31:38 AM3/5/20
to Liberator
Reply all
Reply to author
Forward
Message has been deleted
0 new messages