rabbibotton / clog

CLOG - The Common Lisp Omnificent GUI
Other
1.51k stars 104 forks source link

Upload file with form #92

Closed apr3vau closed 2 years ago

apr3vau commented 2 years ago

Discussed in https://github.com/rabbibotton/clog/discussions/91

Originally posted by **3vau** December 5, 2021 Hello! I'm a noob of clog. I really love its simple and powerful, but when I tried to use clog to upload file to my server through form, I got some trouble. I tried to use post method, just like the way in tutorial 17, and with encoding of "multipart/form-data". but after I submit the form, the form-post-data is still `(("undefined") . nil) `. I also tried to use `post-parameter` in hunchentoot, but it tell me `hunchentoot:*request* is unbound` and it is difficult for me to deal with it. If anyone can give me a direction? Thanks! :)
rabbibotton commented 2 years ago

I am sorry for the delay but I couldn't take the time out from getting CLOG Builder 1.0 out the door :)

I have added the support for file uploads in the last commit.

See clog-form.lisp for FORM-MULTIPART-DATA and DELETE-MULTIPART-DATA to get access to multipart submits and file data.

Here is a small code snip:

(defun on-new-window (body) (let* ((layout (create-panel-box-layout body)) (data (form-multipart-data body))) (center-children (center-panel layout)) (create-ftest (center-panel layout)) (create-div (center-panel layout) :content (form-data-item data "test-val")) (when data (destructuring-bind (stream fname content-type) (form-data-item data "ftest") (let ((s (flexi-streams:make-flexi-stream stream :external-format :utf-8)) (b (make-string 1000))) (loop (let ((c (read-sequence b s))) (unless (plusp c) (return)) (print (subseq b 1 c))))) (delete-multipart-data body))) (run body)))

rabbibotton commented 2 years ago

I added encoding to CREATE-FORM and also updated tutorial 17