Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multipart file upload #63

Closed
knobo opened this issue Jul 3, 2015 · 3 comments
Closed

multipart file upload #63

knobo opened this issue Jul 3, 2015 · 3 comments

Comments

@knobo
Copy link
Contributor

knobo commented Jul 3, 2015

Hi,

How does one upload files to caveman2
I have this simple form, but I'm not able to get the contets.

if caveman2 can not do this, can I inject a hunchentoot handler that does that part?

    <form action="/upload" method="post"  enctype="multipart/form-data">
        <input type="file" name="fileToUpload" id="fileToUpload"/>
      <input id="submit" type="submit" value="Submit">
    </form>
@knobo
Copy link
Contributor Author

knobo commented Jul 8, 2015

I see. #6

The version I downloaded from quicklisp did not include include that fix.
(I'm nut sure what the directory name means. clack-20150302-git )
I will update my distribution.

@knobo knobo closed this as completed Jul 10, 2015
@blasut
Copy link
Contributor

blasut commented Nov 9, 2015

Hi, how do you actually use download and save the file to your local server?

@knobo
Copy link
Contributor Author

knobo commented May 19, 2016

You could try something like this:

(defparameter *file-storage-directory* #p"/var/www/images/")

(defroute ("/upload-image" :method :post) (&key |file|)
  (let ((filename (gethash "filename" (second |file|)))
    (data (slot-value (first |file|) 'flexi-streams::vector)))
    (with-open-file (s (merge-pathnames filename *file-storage-directory*) 
               :if-does-not-exist :create 
               :if-exists :supersede  :direction :output
               :element-type  '(unsigned-byte 8))
      (write-sequence data s)))
  (return-some-result-to-browser))

I'm planning to do something like this in the future (I have not tested it yet):

(setf *image-storage*
      (make-instance 'disk-storage
             :bucket "file-upload-example"
             :directory #P"/tmp/attachment/"))

(defroute ("/upload-image" :method :post) (&key |file|)
  (let ((filename (gethash "filename" (second |file|)))
    (data (first |file|))
    (mito-attachment:*storage* *image-storage*))
    (mito:create-dao 'image :content data)
    (return-some-result-to-browser)))  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants