-
-
Save jgarte/b76f76f531af1bfc49b7bce03d5fe018 to your computer and use it in GitHub Desktop.
Simple hunchentoot server with file form and post handler for the file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-easy-handler (submission-form :uri "/" :default-request-type :get) () | |
(setf (hunchentoot:content-type*) "text/html") | |
(with-html-output-to-string (s) | |
(:html | |
(:head | |
(:title "File Processor") | |
(:style :rel "stylesheet" :type "text/css" | |
(str (css-lite:css (("body") (:background-color "#666")))))) | |
(:body | |
(:form :action "/process" | |
:method :post | |
:enctype "multipart/form-data" | |
(:input :type :file :name "file" :id "file") | |
(:select :name "preset" :id "preset" | |
(dolist (file (directory (merge-pathnames | |
#P"*.txt" | |
(asdf:system-relative-pathname | |
:mnm-file-processor | |
"presets/")))) | |
(htm (:option :value (file-namestring file) | |
(str (file-namestring file)))))) | |
(:input :type :submit :name "submit" :value "submit")))))) | |
(define-easy-handler (submission-handler :uri "/process" :default-request-type :get) () | |
(setf (hunchentoot:content-type*) "text/html") | |
(destructuring-bind (tempfile filename mimetype) (post-parameter "file") | |
(let ((tempfile2 (merge-pathnames filename "/tmp/mnm"))) | |
(uiop:copy-file tempfile tempfile2) | |
(mnm-process-file tempfile2 (merge-pathnames (post-parameter "preset") | |
(asdf:system-relative-pathname | |
:mnm-file-processor | |
"presets/"))) | |
(format nil "~a~%" (namestring tempfile2))))) | |
(defun start-server () | |
(when (and *acceptor* (started-p *acceptor*)) | |
(stop *acceptor*)) | |
(setf *acceptor* (make-instance 'easy-acceptor :port 8080)) | |
(start *acceptor*)) | |
(defun stop-server () | |
(stop *acceptor*)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment