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

Body-parameter streams from chunked multipart data are incomplete #129

Open
wnortje opened this issue Oct 18, 2015 · 2 comments
Open

Body-parameter streams from chunked multipart data are incomplete #129

wnortje opened this issue Oct 18, 2015 · 2 comments

Comments

@wnortje
Copy link

wnortje commented Oct 18, 2015

I am trying to upload files as part of multipart/form-data with chunked encoding. The drakma request is:

 (http-request url :method :post :form-data t
               :parameters 
               `((:recipe . ,recipe)
                 (:content-hash . ,content-hash)
                 (:content-file . (,content-pathname 
                                   :filename ,content-name
                                   :content-type "application/octet-stream"))))

No matter what I do, I can not get the complete uploaded file from the stream obtained from (body-parameter). The stream always ends at the same position partway into the file content.

I think the problem is in this code in http-body.multipart

(loop with buffer = (make-array 1024 :element-type '(unsigned-byte 8))
                for read-bytes = (read-sequence buffer stream)
                do (funcall parser (subseq buffer 0 read-bytes))
                while (= read-bytes 1024))))))

I can get the complete file using (getf (clack.request:env *request*) :raw-body-buffer) but it is not a viable solution for big files because it loads the complete file into RAM.

For the same request (hunchentoot:post-parameter :content-file) returns a pathname to the saved file. This is what I need, but that call breaks Clack.

@wnortje
Copy link
Author

wnortje commented Oct 18, 2015

I made a mistake above. The call (hunchentoot:post-parameter :content-file) can not be used inside a Clack handler because clack.handler.hunchentoot::handle-request reads the stream before (post-parameter) can get to it.

@eudoxia0
Copy link
Contributor

So, why does the upload stream get cut after the first couple kilobytes?

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