clack
clack copied to clipboard
Body-parameter streams from chunked multipart data are incomplete
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.
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.
So, why does the upload stream get cut after the first couple kilobytes?