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

Support uploading directories #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion drakma.asd
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
(:file "cookies")
(:file "encoding")
(:file "request"))
:depends-on (:puri
:depends-on (:uiop
:puri
:cl-base64
:chunga
:flexi-streams
Expand Down
17 changes: 13 additions & 4 deletions request.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,24 @@ depending on the type of CONTENT."
(when (zerop pos) (return))
(write-sequence buf stream :end pos)))))
((pathnamep content)
(with-open-file (from content :element-type 'octet)
;; calls itself with a stream now
(send-content from stream)))
;; Nothing to do for directories.
(when (uiop:file-exists-p content)
(with-open-file (from content :element-type 'octet)
;; calls itself with a stream now
(send-content from stream))))
((or (functionp content)
(and (symbolp content)
(fboundp content)))
(funcall content stream))
(t (parameter-error "Don't know how to send content ~S to server." content)))))

(defun basename (pathname)
(first (last (pathname-directory
;; Ensure directory _after_ truenamizing, otherwise if
;; non-directory file exists it may not yield a directory.
(uiop:ensure-directory-pathname
(uiop:ensure-pathname pathname :truenamize t))))))

(defun make-form-data-function (parameters boundary external-format-out)
"Creates and returns a closure which can be used as an argument for
SEND-CONTENT to send PARAMETERS as a `multipart/form-data' request
Expand Down Expand Up @@ -112,7 +121,7 @@ body using the boundary BOUNDARY."
(file-stream (or (file-namestring file-source)
"user-stream"))
(stream "user-stream")
(pathname (file-namestring file-source)))))
(pathname (basename file-source)))))
(content-type (or (getf (rest value) :content-type)
"application/octet-stream")))
(format stream "; filename=\"~A\"" filename)
Expand Down