unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#16198: 24.3.50; [PATCH 1/2] eww: Does not support file upload.
@ 2013-12-20  9:29 Kenjiro NAKAYAMA
  2013-12-21 20:27 ` Ted Zlatanov
  2013-12-24  7:32 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 7+ messages in thread
From: Kenjiro NAKAYAMA @ 2013-12-20  9:29 UTC (permalink / raw)
  To: 16198

This report includes a patch to eww file upload. Please, review and
install it to the official tree if appreciated.

* Issue
Since Eww does not support file upload(input with type="file"), following
HTML can not display and handle properly.

example:
  <form method="post" action="example.cgi" enctype="multipart/form-data">
    <input name="example" type="file">
    <input type="submit" value="send">
  </form>

Kenjiro NAKAYAMA
  
Signed-off-by: Kenjiro NAKAYAMA <nakayamakenjiro@gmail.com>

        * gnus/mm-url.el (mm-url-encode-multipart-form-data):
          Restore to handle "maltipart/form-data" by eww.
        * net/eww.el(eww-form-file(defface)): New defface of file upload form.
        (eww-submit-file): New key map of file upload.
        (eww-form-file): New file upload button and file name context.
        (eww-select-file): Select file and display selected file name.
        (eww-tag-input): Handle input tag of file type. 
        (eww-update-field): Add point offset.
        (eww-submit): Add submit with multipart/form-data.

---
 lisp/gnus/mm-url.el |  44 +++++++++++++++++++++
 lisp/net/eww.el     | 108 +++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 138 insertions(+), 14 deletions(-)

diff --git a/lisp/gnus/mm-url.el b/lisp/gnus/mm-url.el
index 6e83b18..b8a4d46 100644
--- a/lisp/gnus/mm-url.el
+++ b/lisp/gnus/mm-url.el
@@ -416,6 +416,50 @@ spaces.  Die Die Die."
 
 (autoload 'mml-compute-boundary "mml")
 
+(defun mm-url-encode-multipart-form-data (pairs &optional boundary)
+  "Return PAIRS encoded in multipart/form-data."
+  ;; RFC1867
+  ;; Get a good boundary
+  (unless boundary
+    (setq boundary (mml-compute-boundary '())))
+  (concat
+   ;; Start with the boundary
+   "--" boundary "\r\n"
+   ;; Create name value pairs
+   (mapconcat
+    'identity
+    ;; Delete any returned items that are empty
+    (delq nil
+          (mapcar (lambda (data)
+                    (cond ((equal (car data) "file")
+                           ;; For each pair
+                           (concat
+                            ;; Encode the name
+                            "Content-Disposition: form-data; name=\"" (cdr (assoc "name" (cdr data))) "\"; filename=\"" (cdr (assoc "filename" (cdr data))) "\"\r\n"
+                            "Content-Type: text/plain; charset=utf-8\r\n"
+                            "Content-Transfer-Encoding: binary\r\n\r\n"
+                            (cond ((stringp (cdr (assoc "filedata" (cdr data))))
+                                   (cdr (assoc "filedata" (cdr data))))
+                                  ((integerp (cdr (assoc "filedata" (cdr data))))
+                                   (int-to-string (cdr (assoc "filedata" (cdr data))))))
+                            "\r\n"))
+                          ((equal (car data) "submit")
+                           (concat
+                            "Content-Disposition: form-data; name=\"submit\"\r\n\r\n"
+                            "Submit"
+                            ))
+                          (t
+                           (concat
+                            "Content-Disposition: form-data;name=" (car data) "\r\n\r\n"
+                            (concat (mm-url-form-encode-xwfu (cdr data))
+                                    )))
+                          ))
+                  pairs))
+    ;; use the boundary as a separator
+    (concat "\r\n--" boundary "\r\n"))
+   ;; put a boundary at the end.
+   "--" boundary "--\r\n"))
+
 (defun mm-url-remove-markup ()
   "Remove all HTML markup, leaving just plain text."
   (goto-char (point-min))






^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-11-10 21:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-20  9:29 bug#16198: 24.3.50; [PATCH 1/2] eww: Does not support file upload Kenjiro NAKAYAMA
2013-12-21 20:27 ` Ted Zlatanov
2013-12-24  7:32 ` Lars Ingebrigtsen
2013-12-25  4:29   ` Kenjiro NAKAYAMA
2013-12-25  8:26     ` Lars Ingebrigtsen
2013-12-25 15:09       ` Kenjiro NAKAYAMA
2014-11-10 21:34         ` Lars Magne Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).