You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by "Rian R. Maloney" <ri...@yahoo.com> on 2014/05/14 06:56:11 UTC
multipart/related attachments
I am trying to PUT a multipart document that contains several images using PHP. I have managed to base64 encode the images and issue a PUT but I would prefer to do it w/o base 64 encoding. The socket i/o is hanging as if it is expecting a CRLF terminator - which I have tried many combinations. Here is my log:
Host: 127.0.0.1
Authorization: Basic cmlhbjpwYXNzd29yZA==
Content-Type: multipart/related;boundary="abc123"
--abc123
content-type: application/json
{"body":"This is a body.","_attachments":{"fgs":{"content_type":"text\/plain","follows":"true","length":21},"rgs":{"content_type":"text\/plain","follows":"true","length":20
--abc123
this is 21 chars long
--abc123
this is 20 chars lon
--abc123--
The example in the doc has an extra comma in the json which I assume is an error:
PUT /test_suite_db/multipart HTTP/1.1 Content-Type: multipart/related;boundary="abc123" --abc123 content-type: application/json {"body":"This is a body.", "_attachments":{ "foo.txt": { "follows":true, "content_type":"text/plain", "length":21 }, "bar.txt": { "follows":true, "content_type":"text/plain", "length":20 }, <- EXTRA COMMA } } --abc123 this is 21 chars long --abc123 this is 20 chars lon --abc123--
Any ideas would be much appreciated.
Rian
Re: multipart/related attachments
Posted by Nick North <no...@gmail.com>.
I have a feeling that the problem with data following the final separator was fixed. I'm away for a few days and can't get at the code to check, unfortunately.
Nick
> On 14 May 2014, at 16:51, Jens Alfke <je...@couchbase.com> wrote:
>
> CouchDB’s multipart support is pretty quirky. It’s been a few years since I implemented client code that talks to it, so I don’t remember the details, but a few tips:
> • Make sure all the MIME-related line breaks (before/after the separators and after headers) are CRLFs.
> • IIRC, CouchDB is allergic to any data following the final separator.
> Hope that helps…
>
> —Jens
Re: multipart/related attachments
Posted by Jens Alfke <je...@couchbase.com>.
CouchDB’s multipart support is pretty quirky. It’s been a few years since I implemented client code that talks to it, so I don’t remember the details, but a few tips:
• Make sure all the MIME-related line breaks (before/after the separators and after headers) are CRLFs.
• IIRC, CouchDB is allergic to any data following the final separator.
Hope that helps…
—Jens
Re: multipart/related attachments
Posted by ri...@yahoo.com.
Ok. I assumed my other errors were due to including a length header but now I have a something to work through.
Thanks again!
> On May 15, 2014, at 6:57 PM, Jens Alfke <je...@couchbase.com> wrote:
>
>
>> On May 14, 2014, at 5:48 AM, Rian R. Maloney <ri...@yahoo.com> wrote:
>>
>> Unfortunately nothing is logged in Couch and eventually my socket program will timeout. If I add a content-length header, then couchdb will log an error but the documented example does not include a content-length so I have removed it.
>
> Your client library be using chunked mode to send the body if you don’t give it a content length. And I believe CouchDB doesn’t handle multipart data with chunked encoding … IIRC my co-worker Traun had a lot of trouble with this a month or two ago.
>
> tl;dr you may need to specify a Content-Length header to get this to work.
>
> —Jens
Re: multipart/related attachments
Posted by Nick North <no...@gmail.com>.
Although 1956-attachment-handling should solve your multipart problems, it
causes one of the replication etap tests to fail, so I recommend against
using it for anything other than testing. I will take a look at the look at
the test failure as soon as I can, but it's taking me a while to get to it.
I am in the same position as you, needing better attachment handling for my
own app, so I will fix this.
Nick
On 19 May 2014 12:59, Pieter van der Eems <
p.van.der.eems@interactiveblueprints.nl> wrote:
> We have similar problems with the android client of our app.
> The app uses Couchdbase lite and replicates to a couchdb server
> (couchdb 1.5.0). Adding Attachements (an important task in our app) is
> impossible because anything over 10Kb is send chunked and that does
> not work :-(
>
> Currently I'm trying to make a build with branch
> 1956-attachment-handling in the hope that will solve this.
>
> Met vriendelijke groet,
> Pieter van der Eems
> Interactive Blueprints
>
>
> 2014-05-17 5:54 GMT+02:00 Nick North <no...@gmail.com>:
> > It definitely doesn't handle chunked data encoding for multipart
> requests at the moment. That's in my as-yet-unmerged patch, so I really
> must go and fix the error it causes so that I can merge it.
> >
> > Nick
> >
> >> On 16 May 2014, at 02:57, Jens Alfke <je...@couchbase.com> wrote:
> >>
> >>
> >>> On May 14, 2014, at 5:48 AM, Rian R. Maloney <ri...@yahoo.com>
> wrote:
> >>>
> >>> Unfortunately nothing is logged in Couch and eventually my socket
> program will timeout. If I add a content-length header, then couchdb will
> log an error but the documented example does not include a content-length
> so I have removed it.
> >>
> >> Your client library be using chunked mode to send the body if you don’t
> give it a content length. And I believe CouchDB doesn’t handle multipart
> data with chunked encoding … IIRC my co-worker Traun had a lot of trouble
> with this a month or two ago.
> >>
> >> tl;dr you may need to specify a Content-Length header to get this to
> work.
> >>
> >> —Jens
>
Re: multipart/related attachments
Posted by Pieter van der Eems <p....@interactiveblueprints.nl>.
We have similar problems with the android client of our app.
The app uses Couchdbase lite and replicates to a couchdb server
(couchdb 1.5.0). Adding Attachements (an important task in our app) is
impossible because anything over 10Kb is send chunked and that does
not work :-(
Currently I'm trying to make a build with branch
1956-attachment-handling in the hope that will solve this.
Met vriendelijke groet,
Pieter van der Eems
Interactive Blueprints
2014-05-17 5:54 GMT+02:00 Nick North <no...@gmail.com>:
> It definitely doesn't handle chunked data encoding for multipart requests at the moment. That's in my as-yet-unmerged patch, so I really must go and fix the error it causes so that I can merge it.
>
> Nick
>
>> On 16 May 2014, at 02:57, Jens Alfke <je...@couchbase.com> wrote:
>>
>>
>>> On May 14, 2014, at 5:48 AM, Rian R. Maloney <ri...@yahoo.com> wrote:
>>>
>>> Unfortunately nothing is logged in Couch and eventually my socket program will timeout. If I add a content-length header, then couchdb will log an error but the documented example does not include a content-length so I have removed it.
>>
>> Your client library be using chunked mode to send the body if you don’t give it a content length. And I believe CouchDB doesn’t handle multipart data with chunked encoding … IIRC my co-worker Traun had a lot of trouble with this a month or two ago.
>>
>> tl;dr you may need to specify a Content-Length header to get this to work.
>>
>> —Jens
Re: multipart/related attachments
Posted by Nick North <no...@gmail.com>.
It definitely doesn't handle chunked data encoding for multipart requests at the moment. That's in my as-yet-unmerged patch, so I really must go and fix the error it causes so that I can merge it.
Nick
> On 16 May 2014, at 02:57, Jens Alfke <je...@couchbase.com> wrote:
>
>
>> On May 14, 2014, at 5:48 AM, Rian R. Maloney <ri...@yahoo.com> wrote:
>>
>> Unfortunately nothing is logged in Couch and eventually my socket program will timeout. If I add a content-length header, then couchdb will log an error but the documented example does not include a content-length so I have removed it.
>
> Your client library be using chunked mode to send the body if you don’t give it a content length. And I believe CouchDB doesn’t handle multipart data with chunked encoding … IIRC my co-worker Traun had a lot of trouble with this a month or two ago.
>
> tl;dr you may need to specify a Content-Length header to get this to work.
>
> —Jens
Re: multipart/related attachments
Posted by Jens Alfke <je...@couchbase.com>.
On May 14, 2014, at 5:48 AM, Rian R. Maloney <ri...@yahoo.com> wrote:
> Unfortunately nothing is logged in Couch and eventually my socket program will timeout. If I add a content-length header, then couchdb will log an error but the documented example does not include a content-length so I have removed it.
Your client library be using chunked mode to send the body if you don’t give it a content length. And I believe CouchDB doesn’t handle multipart data with chunked encoding … IIRC my co-worker Traun had a lot of trouble with this a month or two ago.
tl;dr you may need to specify a Content-Length header to get this to work.
—Jens
Re: multipart/related attachments
Posted by "Rian R. Maloney" <ri...@yahoo.com>.
Unfortunately nothing is logged in Couch and eventually my socket program will timeout. If I add a content-length header, then couchdb will log an error but the documented example does not include a content-length so I have removed it.
Re: multipart/related attachments
Posted by Jan Lehnardt <ja...@apache.org>.
What error message are you getting back from CouchDB?
On 14 May 2014, at 06:56 , Rian R. Maloney <ri...@yahoo.com> wrote:
> I am trying to PUT a multipart document that contains several images using PHP. I have managed to base64 encode the images and issue a PUT but I would prefer to do it w/o base 64 encoding. The socket i/o is hanging as if it is expecting a CRLF terminator - which I have tried many combinations. Here is my log:
>
> Host: 127.0.0.1
> Authorization: Basic cmlhbjpwYXNzd29yZA==
> Content-Type: multipart/related;boundary="abc123"
>
> --abc123
> content-type: application/json
>
> {"body":"This is a body.","_attachments":{"fgs":{"content_type":"text\/plain","follows":"true","length":21},"rgs":{"content_type":"text\/plain","follows":"true","length":20
>
> --abc123
>
> this is 21 chars long
> --abc123
>
> this is 20 chars lon
> --abc123--
>
>
> The example in the doc has an extra comma in the json which I assume is an error:
> PUT /test_suite_db/multipart HTTP/1.1 Content-Type: multipart/related;boundary="abc123" --abc123 content-type: application/json {"body":"This is a body.", "_attachments":{ "foo.txt": { "follows":true, "content_type":"text/plain", "length":21 }, "bar.txt": { "follows":true, "content_type":"text/plain", "length":20 }, <- EXTRA COMMA } } --abc123 this is 21 chars long --abc123 this is 20 chars lon --abc123--
> Any ideas would be much appreciated.
>
> Rian