[ https://issues.apache.org/jira/browse/COUCHDB-2295?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15932202#comment-15932202 ]
ASF GitHub Bot commented on COUCHDB-2295: ----------------------------------------- GitHub user stevebest opened an issue: https://github.com/apache/couchdb-nano/issues/36 Streamable multipart attachments are not supported Consider a scenario when you want to upload a document and several attachments to a CouchDB in a single request - a typical example would be uploading a "Couchapp": a design doc with multiple HTML/JS/CSS attachments. This scenario is [supported by CouchDB API](http://docs.couchdb.org/en/1.6.1/api/document/common.html?highlight=multipart/related#creating-multiple-attachments) using `Content-Type: multipart/related` request. Furthermore, you could expect to leverage Node `Stream`s in order to avoid the necessity of buffering a bunch of files in memory. Unfortunately, the combination of issues in CouchDB and `request` prevents this. 1) CouchDB has [a nasty bug](https://issues.apache.org/jira/browse/COUCHDB-2295) which prevents from using `Transfer-Encoding: chunked` along with `Content-Type: multipart/related`. It won't be fixed until `1.7`, and its status in `2.x` branch is unknown. 2) `request` uses exactly the `Transfer-Encoding: chunked` to upload data from `Stream`s. Uh-oh. 3) `request` could be told explicitly not to use `chunked` encoding - but then you can't give it any `Stream`s! See [docs for a `multipart` option in request(options, callback)](https://github.com/request/request#requestoptions-callback). Bummer. Technically, it should be possible to stream a bunch of attachments, in case where one knows the length of the stream beforehand (which is not a problem when you upload files from a disk). I attempted to add the support for this case in dscape/nano#300, but failed miserably because `request` rightfully thinks it's smarter than me. ---- ---- > Connection hangs on document update for multipart/related and transfer > encoding chunked request > ----------------------------------------------------------------------------------------------- > > Key: COUCHDB-2295 > URL: https://issues.apache.org/jira/browse/COUCHDB-2295 > Project: CouchDB > Issue Type: Bug > Components: HTTP Interface > Reporter: Alexander Shorin > Fix For: 1.7.0 > > > Script to reproduce: > {code} > import pprint > import requests > body = [ > b'--996713c691ec4fd5b717ef2740893b78\r\n', > b'Content-Type: application/json\r\n', > b'\r\n', > b'{"_id": "test","_attachments": {"foo": {"follows": true, > "content_type": "text/plain", "length": 12}}}\r\n', > b'--996713c691ec4fd5b717ef2740893b78\r\n', > b'Content-Type: text/plain\r\n' > b'Content-Disposition: attachment;filename="foo"\r\n' > b'Content-Length: 12\r\n' > b'\r\n', > b'Time to Relax!', > b'--996713c691ec4fd5b717ef2740893b78--\r\n' > ] > url = 'http://localhost:5984/db/test' > headers = { > 'Content-Type': 'multipart/related; > boundary="996713c691ec4fd5b717ef2740893b78"' > } > resp = requests.put(url, headers=headers, data=iter(body)) > pprint.pprint(resp.json()) > {code} > This runs a request: > {code} > PUT /db/test HTTP/1.1 > Host: localhost:5984 > Accept-Encoding: gzip, deflate > Transfer-Encoding: chunked > User-Agent: python-requests/2.3.0 CPython/3.4.1 Linux/3.15.5-gentoo > Accept: */* > Content-Type: multipart/related; boundary="996713c691ec4fd5b717ef2740893b78" > 24 > --996713c691ec4fd5b717ef2740893b78 > 20 > Content-Type: application/json > 2 > 68 > {"_id": "test","_attachments": {"foo": {"follows": true, "content_type": > "text/plain", "length": 14}}} > 24 > --996713c691ec4fd5b717ef2740893b78 > 60 > Content-Type: text/plain > Content-Disposition: attachment;filename="foo" > Content-Length: 12 > e > Time to Relax! > 26 > --996713c691ec4fd5b717ef2740893b78-- > 0 > {code} > But connection hangs: CouchDB thinks that there have to more data while zero > length chunk had been send and doesn't reply with anything back to client > which had finished the request and awaits for the response. > The problem could be "fixed" by specifying full Content-Length of multipart > body in request, which kills all the idea of chunked transfer. -- This message was sent by Atlassian JIRA (v6.3.15#6346)