Re: File upload

"Emond, Bruno" <[email protected]> Mon, 26 Jan 2004 12:36:38 -0500
Newsgroups gmane.lisp.cl-http
Message-ID <BC3ABA56.F172%[email protected]>
David, 

Here is a short example. It works fine with small files. Although, I have
tested the code with MCL 5.0 and for large files it hangs.

Bruno

(defmethod make-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)
        (html:with-fillout-form   (:post url :stream stream :encoding-type
'(:multipart :form-data))
          (html:with-paragraph (:stream stream)
            (html:accept-input 'html2:file "uploadfile" :stream stream))
          (html:with-paragraph (:stream stream)
            (html:accept-input 'html:submit-button "submit" :stream
stream)))))))

(setf http:*file-upload-default-directory* "Uplaod-directory:")

(defun response-to-post (url stream query-alist)
  (http:bind-query-values (uploadfile)
                          (url:url query-alist)
    (if uploadfile
      (http:with-successful-response
        (stream :html)
        (html:with-html-document (:stream stream)
          (html:with-document-preamble (:stream stream)
            (html:declare-title "Upload-result" :stream stream))
          (html:with-document-body (:stream stream)
            (html:with-fillout-form   (:post url :stream stream
:encoding-type '(:multipart :form-data))
              (html:with-paragraph (:stream stream)
                (fast-format stream "~A" uploadfile))))))
      (make-form url stream))))

(export-url #u"/my-upload.html"
            :html-computed-form
            :response-function #'response-to-post
            :form-function #'make-form)



> From: David Johnson-Davies <[email protected]>
> Date: Wed, 10 Dec 2003 12:39:38 -0500
> To: [email protected]
> Subject: File upload
> 
> Has anyone got a working example of file-upload that works with CL-HTTP
> using (accept-input 'file ...).
> 
> Thanks,
> David Johnson-Davies
> 
> +------------------------------------------------------------+
> David Johnson-Davies, Human-Computer Interface Ltd
> 17 Signet Court, Swanns Road, Cambridge, CB5 8LA, England.
> 
> Tel: +44 1223 314934, Fax: +44 1223 462562
> Email: [email protected], Web: http://www.interface.co.uk/
> +------------------------------------------------------------+
> 
>