Next: , Previous: , Up: Usage Examples   [Contents][Index]

4.9 File Upload

The following example demonstrates accessing an uploaded file. This simple server accesses the file named “file” and returns it’s sha1sum and file name.

;;; file-upload.el --- use an uploaded file
 '(((:POST . ".*") .
    (lambda (request)
      (with-slots (process headers) request
        (ws-response-header process 200 '("Content-type" . "text/plain"))
        (let ((file (cdr (assoc "file" headers))))
          (process-send-string process
            (concat (sha1 (cdr (assoc 'content file))) "  "
                    (cdr (assoc 'filename file)) "\n")))))))

A file may be uploaded from an HTML form, or using the curl program as in the following example.

$ curl -s -F file=usr/share/emacs/24.3/etc/COPYING localhost:9008
8624bcdae55baeef00cd11d5dfcfa60f68710a02  COPYING
$ sha1sum /usr/share/emacs/24.3/etc/COPYING
8624bcdae55baeef00cd11d5dfcfa60f68710a02  /usr/share/emacs/24.3/etc/COPYING