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

Handling uploads #32

Open
mishoo opened this issue Feb 15, 2018 · 1 comment
Open

Handling uploads #32

mishoo opened this issue Feb 15, 2018 · 1 comment

Comments

@mishoo
Copy link

mishoo commented Feb 15, 2018

I couldn't find any officially documented way to get uploads. After much digging, I figured out I need to (lack.request:make-request env) and then I can use (lack.request:request-parameters req). My code looks like this:

  (let* ((params (lack.request:request-parameters req))
         (file (cdr (assoc "file" params :test #'string=)))
         (token (cadr (assoc "token" params :test #'string=))))
    (destructuring-bind (input-stream params1 params2) file
      (let ((filename (gethash "filename" params1))
            (mimetype (gethash "content-type" params2)))
        (make-file filename mimetype input-stream token)))

It works, but I feel like using private APIs. The parameters appear to be an alist, associating the parameter name with a list of things; to get the value of the token, for example, I need to use (cadr (assoc "token" params)). Also, for the file I get an in-memory stream and two hashes, one containing the file name and the other containing the content-type.

My question is, is this code future-proof, or is the API supposed to change? (or is there some better API that I failed to find?)

@fukamachi
Copy link
Owner

Lack.Request is an open API.

I agree with the structure isn't understandable very much, however, it's taken from Hunchentoot's.
More useful helper function might be added, but the API (and its structure) won't be changed, I think.

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