Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The with-html-form seems to fail uploading a file #1

Open
naryl opened this issue Oct 2, 2020 · 6 comments
Open

The with-html-form seems to fail uploading a file #1

naryl opened this issue Oct 2, 2020 · 6 comments

Comments

@naryl
Copy link

naryl commented Oct 2, 2020

(with-html-form (:post (lambda (&key new-name description file &allow-other-keys)
                         (create-or-update-chapter name new-name description file))
                 :enctype "multipart/form-data")
  (:input :name "new-name" :value name) (:br)
  (:textarea :name "description") (:br)
  (:input :type "file" :name "file") (:br)
  (:input :type "submit" :value "Submit"))))

The form Action doesn't get the :file keyword argument.

@svetlyak40wt
Copy link
Member

Interesting. I've never tried it. Seems like a bug.

Please, try to fix it and let me know if you'll need some help.

@naryl
Copy link
Author

naryl commented Oct 2, 2020

https://github.com/40ants/weblocks/blob/reblocks/src/js/jquery/jquery.js#L12

https://api.jquery.com/serializeArray/

Data from file select elements is not serialized.

Also, my code works correctly with Javascript disabled which makes it a full non-ajax request. I have no idea what to do about it.

@naryl
Copy link
Author

naryl commented Oct 2, 2020

Well, the workaround is to disable ajax for this form. weblocks can already do it. But can we fix it to make ajax upload work too?

@svetlyak40wt
Copy link
Member

Could you please create a minimal app.lisp file to reproduce and experiment with this problem and post it here or upload as to the https://gist.github.com/?

@naryl
Copy link
Author

naryl commented Oct 2, 2020

(in-package :cl-user)

(eval-when (:compile-toplevel :load-toplevel :execute)
  (ql:quickload '(:weblocks :weblocks-ui)))

(weblocks/app:defapp upload-test :prefix "/")

(defmethod weblocks/session:init ((app upload-test))
  (make-instance 'main))

(weblocks/widgets/base:defwidget main () ())

(defmethod weblocks/widgets/base:render ((main main))
  (weblocks-ui/form:with-html-form (:post (lambda (&key file &allow-other-keys)
                                            (format t "*** FILE UPLOAD: ~S" file))
                                          :enctype "multipart/form-data")
    (:input :type "file" :name "file") (:br)
    (:input :type "submit" :value "Submit")))

(weblocks/server:start)

Just load it.

@svetlyak40wt
Copy link
Member

I've tested it myself.

Unless you disable Ajax with :use-ajax-p nil, Weblocks posts form data as json with Content-Type: application/json ignoring your :enctype "multipart/form-data".

Thus, the only option is to add :use-ajax-p nil.

It will be a good to add a weblocks-ui/form:with-upload-form, which will have :post :enctype "multipart/form-data" :use-ajax-p nil by default.

@svetlyak40wt svetlyak40wt transferred this issue from 40ants/weblocks-ui Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants