clog
clog copied to clipboard
Javascript upload fails by unknown reason
Here the code I try to use, I tried to debug it but I can't see any reason why it fails.
It seems the function bound to "/upload" does not get executed when called from JavaScript.
Uploading with :method :post :action "/upload"
does work fine but I can't manage to make the JavaScript one work.
Thank you for your time!
(defun on-upload (clog-body body)
(declare (ignore clog-body))
(setf (inner-html body) "")
(with-clog-create body
(div (:bind upload)
(form (:bind u-form
:encoding "multipart/form-data")
(legend (:content "Upload post"))
(form-element (:bind u-finput :file :name "filename" :html-id "uFinput"))
(form-element (:submit))))
(setf (multiplep u-finput) t)
(debug-mode u-form)
(clog::set-event u-form "submit"
(lambda (data)
(declare (ignore data)))
:cancel-event t
:eval-script (ps:ps
(ps:chain event (prevent-default))
(let ((data-form (ps:new (*form-data))))
(loop :for file :across (ps:chain document (get-element-by-id "uFinput") files)
:do (ps:chain data-form (append "file" file)))
;; (ps:delete (ps:chain options headers "Content-Type"))
(ps:chain console (log fetch "/upload" (ps:create method "POST" body data-form))))))))
Not sure I understand what you are trying to accomplish here and why using set-event? (sorry for the delay getting to this)
No reloading of the page when uploading files!
Trying setting :method in create-form