zengod
zengod

Reputation: 1174

How to extract the form data from a request in 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?

Upvotes: 1

Views: 163

Answers (0)

Related Questions