How do you accept file uploads in noir

I have a file input setup similar to this

[:p "Upload a book"] (form-to [:post "/upload"] (file-upload :book) (submit-button "Upload")) 

Then my download endpoint is as follows.

 (defpage [:post "/upload"] {:keys [book]} (println book)) 
Book

It seems like just the title bar of the downloaded file, not the file itself. How to get a file?

+6
source share
2 answers

According to this topic (see Chris Granger's second post):

you can use something like:

 (defpage [:post "upload"] {:keys [myFile]} (println myFile) ;; see all the things the file contains (io/copy (io/file (:tempfile myFile)) (io/file "uploads/some-new-name"))) 

Here is the gist of this topic:

with a note (again from Chris) that you need Leiningen 1.6.1.1+ not to get into error.

You can see a similar thing (albeit for Amazon S3) here:

Hope this helps.

+4
source

I think you agree; I believe that you are publishing incorrectly. Try form-to {:enctype "multipart/form-data"} or from the curl --form book=@ /home/me/Penguins.jpg http://localhost:8080/Upload shell curl --form book=@ /home/me/Penguins.jpg http://localhost:8080/Upload

+2
source

Source: https://habr.com/ru/post/907901/


All Articles