Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D64FD107D1 for ; Wed, 11 Dec 2013 13:19:22 +0000 (UTC) Received: (qmail 90202 invoked by uid 500); 11 Dec 2013 13:19:20 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 90169 invoked by uid 500); 11 Dec 2013 13:19:19 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 90161 invoked by uid 99); 11 Dec 2013 13:19:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Dec 2013 13:19:19 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [81.169.146.161] (HELO mo-p00-ob.rzone.de) (81.169.146.161) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Dec 2013 13:19:15 +0000 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1386767933; l=33598; s=domk; d=gonvaled.com; h=Content-Type:To:Subject:Date:From:References:In-Reply-To: MIME-Version:X-RZG-CLASS-ID:X-RZG-AUTH; bh=DAxThjSlNbp0AjUWmsGLW1jP0QM=; b=yCClJlvCfNx42CZ0NtJENiOOlyQ938pxTmWKcU3Ms0NrMWzI5RL69BdqdsZyMmxbcEX UdngQBeITBwC9Hejo9dRs8hrdeG77n1Yo3RHlFenxsYLTkiSAH8qTnFifQV6CrQMRZ2fv kALRBogFmbe1VQIhlWBZjp/YF6s7onh4aCE= X-RZG-AUTH: :K2MKY0GkfvuAYI9OvLYEA55J0qvTZZULi9CTHjqnn8/d41Z9VA5z1TAdiByBSJxL X-RZG-CLASS-ID: mo00 Received: from mail-ob0-f180.google.com ([209.85.214.180]) by smtp.strato.de (RZmta 32.17 AUTH) with (TLSv1:DHE-RSA-AES256-SHA encrypted) ESMTPSA id 605e59pBBDIqEkR for ; Wed, 11 Dec 2013 14:18:52 +0100 (CET) Received: by mail-ob0-f180.google.com with SMTP id wo20so6890509obc.39 for ; Wed, 11 Dec 2013 05:18:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=zrK5ezec/I/lr8ZC6RP7B+Nq0q3Mph5R2e+TkbUIMRE=; b=DsmzLEUnyMvXesseaOlo+tOVA4y+1hsX4G878PiayKO0Qd4eFSfwmB6HD80sR+StDZ HLVEGMqNbaXUgcep/pVnkwbt81PyB2ze243ZTdutj4OTWbhqYYLzrvwPIvwBmA5nj7q+ DUZiU32Vw+2QrMPgQkSMaid026CiJWPds1g69iKBRS4gP0qajCmmlAbjBPTOLkX9XOYA OHZoWV1DK/L0CSXot5+qtuaE9GKc5sQMyu/K5IuOJrQ3piUvejWE3sqGTk9ggkl0xXQM SE4DRqJBmjfUT7BiLhbzWz+Spuds/dL77VkhvkhnHAE6qRS9P/ozPPVG1tWM5uSMFdWx bimw== X-Received: by 10.182.158.71 with SMTP id ws7mr1102357obb.6.1386767932141; Wed, 11 Dec 2013 05:18:52 -0800 (PST) MIME-Version: 1.0 Received: by 10.76.133.100 with HTTP; Wed, 11 Dec 2013 05:18:22 -0800 (PST) In-Reply-To: References: From: Daniel Gonzalez Date: Wed, 11 Dec 2013 14:18:22 +0100 Message-ID: Subject: Re: bulk update failing when document has attachments? To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=089e01494a16fb84ce04ed4211ca X-Virus-Checked: Checked by ClamAV on apache.org --089e01494a16fb84ce04ed4211ca Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Funny that you do not need to escape it. The spec says you should: char any-Unicode-character- except-"-or-\-or- control-character \" \\ \/ \b \f \n \r \t \u four-hex-digits Anyway, my problem has been solved. I am not escaping anything in the content_type: the json library is problably doing that. What I need to do is to attach real base64 encoded data, which has solved my problem. On Wed, Dec 11, 2013 at 2:15 PM, Robert Newson wrote: > =E2=9E=9C ~ curl localhost:5984/db1/_bulk_docs > -Hcontent-type:application/json -d > '{"docs":[{"_attachments":{"foo":{"data":"aGVsbG8=3D"}}}]}' > > [{"ok":true,"id":"b5d2060479624e483a8fe4747f001dbe","rev":"1-12c665c499a5= 25a3a1a9ad35c90604a1"}] > > =E2=9E=9C ~ curl localhost:5984/db1/b5d2060479624e483a8fe4747f001dbe > > {"_id":"b5d2060479624e483a8fe4747f001dbe","_rev":"1-12c665c499a525a3a1a9a= d35c90604a1","_attachments":{"foo":{"content_type":"application/octet-strea= m","revpos":1,"digest":"md5-XUFAKrxLKna5cZ2REBfFkg=3D=3D","length":5,"stub"= :true}}} > > =E2=9E=9C ~ curl localhost:5984/db1/b5d2060479624e483a8fe4747f001dbe/fo= o > hello% > > Maybe you left escaped newlines in your base64 input? > > B. > > > On 11 December 2013 13:11, Robert Newson wrote: > > http://json.org/string.gif talks escaping back slash, not forward > > slash. The PDF page 194 talks about escaping forward slash within a > > RegExp statement in Javascript, which is not JSON. > > > > B. > > > > > > On 11 December 2013 12:58, Daniel Gonzalez > wrote: > >> It is not an artifact: I am taking that from the couchdb documentation= . > >> > >> And according to Alexander Shorin forward slashes **really** need to b= e > >> escaped in json. But it is not me who must do that, but the library > >> converting the python objects to couchdb, so that can not be my proble= m. > >> > >> Now I am left with a badarg exception, which I can not relate to my > input > >> data: > >> > >> Exception > Problems updating list of documents (length =3D 1): (500, > >> ('badarg', '46')) > >> > >> What does that '46' mean? > >> > >> > >> On Wed, Dec 11, 2013 at 1:47 PM, Robert Newson > wrote: > >> > >>> I think your "image\/png" is just an artifact of your printing method= , > >>> you don't need to escape the forward slash in content_type, see > >>> example below; > >>> > >>> > >>> > {"_id":"doc1","_rev":"1-96e2a6c78b8bfb227e79e1fbb16873f9","_attachments":= {"att1":{"content_type":"image/png","revpos":1,"digest":"md5-XUFAKrxLKna5cZ= 2REBfFkg=3D=3D","length":5,"stub":true}}} > >>> > >>> B. > >>> > >>> > >>> On 11 December 2013 12:35, Daniel Gonzalez > wrote: > >>> > That would work *only* for that prefix (data:image/png;base64,), or > any > >>> > prefix which happens to have the same length. Not very robust. > >>> > > >>> > I just discovered that the data coming from the front-end comes in > >>> data-uri > >>> > format (rfc2397). This should handle any rfc2397 prefix: > >>> > http://stackoverflow.com/a/20518589/647991 (maybe buggy, just > >>> implemented). > >>> > > >>> > Another question: even after removing the data-uri prefix, I am sti= ll > >>> > getting problems. I think my content type is not right. > >>> > > >>> > Must content_type be escaped? That is: > >>> > > >>> > 'content_type': 'image/png', -> 'content_type': 'image\/png', > >>> > > >>> > The only reference I see to that is an example here: > >>> > http://wiki.apache.org/couchdb/HTTP_Document_API#Inline_Attachments > >>> > > >>> > But no real explanation of why. It seems no other strings must be > escaped > >>> > for couchdb. The only requirement that couchdb seems to impose on > top of > >>> > json is that the data in the attachment must be in base64 format. > >>> > > >>> > But now it seems that the content_type must escape the slashes (/). > Why? > >>> It > >>> > does not seem to be a json feature: slashes are fine in any json > string. > >>> So > >>> > what is that? > >>> > > >>> > I would like to know the specificacion for the format expected for > >>> > content_type. Does that have a name? I am calling it "escaped > mediatype". > >>> > Is it part of a more generic escaping process expected by couchdb, = or > >>> only > >>> > the content_type is affected? Is there an official name for that? > >>> > > >>> > > >>> > On Wed, Dec 11, 2013 at 12:18 PM, Johannes J=C3=B6rg Schmidt < > >>> > schmidt@netzmerk.com> wrote: > >>> > > >>> >> data.slice(22) > >>> >> > >>> >> 2013/12/11 Daniel Gonzalez : > >>> >> > Thanks, I just realized about this. The base64 is coming from th= e > >>> >> > javascript frontend (chose file in a form). So I need to remove > the > >>> >> > prefix "data:image/png;base64,". > >>> >> > Not sure how to do this without rolling my own regexes though. > >>> >> > > >>> >> > > >>> >> > On Wed, Dec 11, 2013 at 12:01 PM, Alexander Shorin < > kxepal@gmail.com> > >>> >> wrote: > >>> >> > > >>> >> >> Hi, > >>> >> >> > >>> >> >> _attachments data should be valid base64 encoded string, while > you > >>> have: > >>> >> >> > > >>> >> >> > >>> >> > >>> > data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM8AAADkCAIAAACwiOf9AAAAA3N= CSVQICAjb4U/gAAAgAElEQVR4nO... > >>> >> >> > >>> >> >> Chars : and , are invalid for base64. > >>> >> >> -- > >>> >> >> ,,,^..^,,, > >>> >> >> > >>> >> >> > >>> >> >> On Wed, Dec 11, 2013 at 2:49 PM, Daniel Gonzalez < > >>> gonvaled@gonvaled.com > >>> >> > > >>> >> >> wrote: > >>> >> >> > Hi, > >>> >> >> > > >>> >> >> > (SO reference: http://stackoverflow.com/q/20516980/647991. I > post > >>> >> there > >>> >> >> > because formatting makes things much easier to read, replies = / > >>> >> comments > >>> >> >> are > >>> >> >> > well organized, and the up/downvote mechanism works) > >>> >> >> > > >>> >> >> > I am performing the following operation: > >>> >> >> > > >>> >> >> > 1. Prepare some documents: `docs =3D [ doc1, doc2, ... ]`. Th= e > >>> documents > >>> >> >> have > >>> >> >> > *maybe* attachments > >>> >> >> > 2. I `POST` to `_bulk_docs` the list of documents > >>> >> >> > 3. I get an `Exception > Problems updating list of documents > >>> (length =3D > >>> >> >> 1): > >>> >> >> > (500, ('badarg', '58'))` > >>> >> >> > > >>> >> >> > My `bulk_docs` is (in this case just one): > >>> >> >> > > >>> >> >> > [ { '_attachments': { 'image.png': { > 'content_type': > >>> >> >> > 'image/png', > >>> >> >> > 'data': > >>> >> >> > > >>> >> >> > >>> >> > >>> > 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM8AAADkCAIAAACwiOf9AAAAA3= NCSVQICAjb4U/gAAAgAElEQVR4nO...'}}, > >>> >> >> > '_id': '08b8fc66-cd90-47a1-9053-4f6fefabdfe3', > >>> >> >> > '_rev': '15-ff3d0e8baa56e5ad2fac4937264fb3f6', > >>> >> >> > 'docmeta': { 'created': '2013-10-01 > 14:48:24.311257', > >>> >> >> > 'updated': [ '2013-10-01 > >>> >> 14:48:24.394157', > >>> >> >> > '2013-12-11 > >>> >> 08:19:47.271812', > >>> >> >> > '2013-12-11 > >>> >> 08:25:05.662546', > >>> >> >> > '2013-12-11 > >>> >> 10:38:56.116145']}, > >>> >> >> > 'org_id': 45345, > >>> >> >> > 'outputs_id': None, > >>> >> >> > 'properties': { 'auto-t2s': False, > >>> >> >> > 'content_type': 'image/png', > >>> >> >> > 'lang': 'es', > >>> >> >> > 'name': 'dfasdfasdf', > >>> >> >> > 'text': 'erwerwerwrwerwr'}, > >>> >> >> > 'subtype': 'voicemail-st', > >>> >> >> > 'tags': ['RRR-ccc-dtjkqx'], > >>> >> >> > 'type': 'recording'}] > >>> >> >> > > >>> >> >> > This is the detailed exception: > >>> >> >> > > >>> >> >> > Traceback (most recent call last): > >>> >> >> > File "portal_support_ut.py", line 470, in test_UpdateDo= c > >>> >> >> > self.ps.UpdateDoc(self.org_id, what, doc_id, new_data= ) > >>> >> >> > File > >>> >> >> > > >>> >> >> > >>> >> > >>> > "/home/gonvaled/projects/new-wavilon-portal/python_modules/wav/ps/complex= _ops.py", > >>> >> >> > line 349, in UpdateDoc > >>> >> >> > success, doc =3D database.UpdateDoc(doc_id, new_data) > >>> >> >> > File > >>> >> >> > > >>> >> >> > >>> >> > >>> > "/home/gonvaled/projects/new-wavilon-portal/python_modules/wav/cdb/core/u= pdater.py", > >>> >> >> > line 38, in UpdateDoc > >>> >> >> > res =3D self.SaveDoc(doc_id, doc) > >>> >> >> > File > >>> >> >> > > >>> >> >> > >>> >> > >>> > "/home/gonvaled/projects/new-wavilon-portal/python_modules/wav/cdb/core/s= aver.py", > >>> >> >> > line 88, in SaveDoc > >>> >> >> > else : self.bulk_append(doc, flush, > update_revision) > >>> >> >> > File > >>> >> >> > > >>> >> >> > >>> >> > >>> > "/home/gonvaled/projects/new-wavilon-portal/python_modules/wav/cdb/core/b= ulker.py", > >>> >> >> > line 257, in bulk_append > >>> >> >> > if force_send or flush or not self.timer.use_timer : > >>> >> >> > self.BulkSend(show_progress=3DTrue) > >>> >> >> > File > >>> >> >> > > >>> >> >> > >>> >> > >>> > "/home/gonvaled/projects/new-wavilon-portal/python_modules/wav/cdb/core/b= ulker.py", > >>> >> >> > line 144, in BulkSend > >>> >> >> > results =3D self.UpdateDocuments(self.bulk) > >>> >> >> > File > >>> >> >> > > >>> >> >> > >>> >> > >>> > "/home/gonvaled/projects/new-wavilon-portal/python_modules/wav/cdb/core/b= ulker.py", > >>> >> >> > line 67, in UpdateDocuments > >>> >> >> > results =3D self.db.update(bulkdocs) > >>> >> >> > File > >>> >> >> > > >>> >> >> > >>> >> > >>> > "/home/gonvaled/.virtualenvs/python2.7.3-wavilon1/local/lib/python2.7/sit= e-packages/couchdb/client.py", > >>> >> >> > line 764, in update > >>> >> >> > _, _, data =3D self.resource.post_json('_bulk_docs', > >>> >> body=3Dcontent) > >>> >> >> > File > >>> >> >> > > >>> >> >> > >>> >> > >>> > "/home/gonvaled/.virtualenvs/python2.7.3-wavilon1/local/lib/python2.7/sit= e-packages/couchdb/http.py", > >>> >> >> > line 527, in post_json > >>> >> >> > **params) > >>> >> >> > File > >>> >> >> > > >>> >> >> > >>> >> > >>> > "/home/gonvaled/.virtualenvs/python2.7.3-wavilon1/local/lib/python2.7/sit= e-packages/couchdb/http.py", > >>> >> >> > line 546, in _request_json > >>> >> >> > headers=3Dheaders, **params) > >>> >> >> > File > >>> >> >> > > >>> >> >> > >>> >> > >>> > "/home/gonvaled/.virtualenvs/python2.7.3-wavilon1/local/lib/python2.7/sit= e-packages/couchdb/http.py", > >>> >> >> > line 542, in _request > >>> >> >> > credentials=3Dself.credentials) > >>> >> >> > File > >>> >> >> > > >>> >> >> > >>> >> > >>> > "/home/gonvaled/.virtualenvs/python2.7.3-wavilon1/local/lib/python2.7/sit= e-packages/couchdb/http.py", > >>> >> >> > line 398, in request > >>> >> >> > raise ServerError((status, error)) > >>> >> >> > ServerError: (500, ('badarg', '58')) > >>> >> >> > > >>> >> >> > > >>> >> >> > What does that `badarg` mean? Is it possible to send > attachments > >>> when > >>> >> >> doing > >>> >> >> > `_bulk_docs`? > >>> >> >> > > >>> >> >> > Thanks, > >>> >> >> > Daniel > >>> >> >> > >>> >> > >>> > --089e01494a16fb84ce04ed4211ca--