clog icon indicating copy to clipboard operation
clog copied to clipboard

Javascript upload fails by unknown reason

Open ebrasca opened this issue 1 year ago • 3 comments

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))))))))

ebrasca avatar Jul 22 '23 10:07 ebrasca

Not sure I understand what you are trying to accomplish here and why using set-event? (sorry for the delay getting to this)

rabbibotton avatar Jan 16 '24 00:01 rabbibotton

No reloading of the page when uploading files!

ebrasca avatar Jan 21 '24 00:01 ebrasca

Trying setting :method in create-form

rabbibotton avatar Jan 26 '24 14:01 rabbibotton