[Prev][Next][Index][Thread]
Who can give me an example for "Form upload"
With the Netscape 2.0 browser it is possible to upload files to
the server. This is a very convenient feature for site administration.
Or think of providing some kind of conversion mechnanism (example:
lisp -> fasl, mif -> html, ...) with a server interface.
Here is some code:
; let's have a response function - it has no query-alist
(defgeneric respond-to-upload (url stream))
; question: what would I have to do to decode the data I'm getting?
; this method "hangs" after reading from the stream.
(defmethod respond-to-upload ((url url:http-form) stream)
(let ((lines (loop for line = (read-line stream nil nil)
while line
count line
do (princ line))))
(http:with-successful-response (stream :html)
(html:with-html-document (:stream stream)
(html:with-document-preamble (:stream stream)
(html:declare-title "done" :stream stream))
(html:with-document-body (:stream stream)
(princ lines stream))))))
(defmethod emit-upload-form ((url url:http-form) stream)
(http:with-successful-response (stream :html)
(html:with-html-document (:stream stream)
(html:with-document-preamble (:stream stream)
(html:declare-title "Upload" :stream stream))
(html:with-document-body (:stream stream)
(netscape2.0:with-fillout-form (:post url :stream stream :encoding-type '(:multipart :form-data))
(princ "Send file: " stream)
(netscape2.0:accept-input 'netscape2.0::file "UPLOAD" :stream stream)
(html:accept-input 'html:submit-button "Submit" :stream stream))))))
(http:export-url #u"/test.html"
:html-computed-form
:form-function #'emit-upload-form
:response-function #'respond-to-upload)
Greetings from Hamburg,
Rainer Joswig
Follow-Ups: