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 5C6F310A8B for ; Fri, 3 Jan 2014 16:34:16 +0000 (UTC) Received: (qmail 79881 invoked by uid 500); 3 Jan 2014 16:34:13 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 78585 invoked by uid 500); 3 Jan 2014 16:34:08 -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 78426 invoked by uid 99); 3 Jan 2014 16:34:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Jan 2014 16:34:05 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS,WEIRD_PORT 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.163] (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.163) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Jan 2014 16:34:00 +0000 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1388766818; l=12988; 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=m4UTdvVU6v5gqhgYyC3b/WFxKrc=; b=iavH+Sm/+zoDLgILXZK4ih9G7mYUwM+GmUYlalurH1GitzrJSXdMBucQNKj2CuEAexC 9rmwk+oO0Cs96dZep5/akVLdCv7ehic1C8tQC67iY2uCAhs3OItCeEZaixRqTxRMvpoms T7qVwUxjGdRX/6eCY5J+1HMi6Vp233fIN3I= X-RZG-AUTH: :K2MKY0GkfvuAYI9OvLYEA55J0qvTZZULi9CTHjqnn8/d41Z9VA5z1TAdiByBR5pL X-RZG-CLASS-ID: mo00 Received: from mail-ob0-f176.google.com ([209.85.214.176]) by smtp.strato.de (RZmta 32.17 AUTH) with (TLSv1:DHE-RSA-AES256-SHA encrypted) ESMTPSA id y01466q03GXbvz9 for ; Fri, 3 Jan 2014 17:33:37 +0100 (CET) Received: by mail-ob0-f176.google.com with SMTP id vb8so15654830obc.7 for ; Fri, 03 Jan 2014 08:33:37 -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=3pWROIgK4lM/y8NOOXdquohdHM1ZhUejInWugOHtnBE=; b=ZQlp8YzRWCP0HtOjNmdSPAV86rObcqV5udLwTAtqHlQagYb57LraT8c3LGslWfZRXK TlvEcK5QiQr1/NI7YQjXMEypIeVJPaQ/cJ1tM5QBfteivo+0SDsK+knhesqMypZejCbn tygiQzgdj79iPjKFRw/V4j8pyMwofZ7pn6ePLfcyQo3eX/rNn08v0K8asWNfZADnmye3 wSo0GULDr5qvhS2pdA0vd4Ogr6UQS5GZqApMlDawp3yUX7Y5byOvdttaMrJBm2304zLt 3dR/s3tgGljAjPN5kcxMd2mRm42N/ibJpffV5zXV/2s/7sqNQwpK180lhGm62fnzCB+a 4NPA== X-Received: by 10.182.81.197 with SMTP id c5mr60875600oby.40.1388766816984; Fri, 03 Jan 2014 08:33:36 -0800 (PST) MIME-Version: 1.0 Received: by 10.76.133.100 with HTTP; Fri, 3 Jan 2014 08:33:06 -0800 (PST) In-Reply-To: References: From: Daniel Gonzalez Date: Fri, 3 Jan 2014 17:33:06 +0100 Message-ID: Subject: Re: Specify attachment encoding for couchdb To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=047d7b2e4d58cd67f004ef1378ed X-Virus-Checked: Checked by ClamAV on apache.org --047d7b2e4d58cd67f004ef1378ed Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable Great! That is exactly what I was looking for! Thanks! On Fri, Jan 3, 2014 at 5:08 PM, Nick North wrote: > Cunning :-) > > > On 3 January 2014 15:48, Alexander Shorin wrote: > > > Erhm..just replace: > > > > > db.put_attachment(doc, content, content_type=3D'text/plain') > > > > with > > > > > db.put_attachment(doc, content, > content_type=3D'text/plain;charset=3Dutf-8') > > > > And CouchDB will remember it: > > > > $ http HEAD http://localhost:5984/b/testing/test > > HTTP/1.1 200 OK > > Accept-Ranges: none > > Cache-Control: must-revalidate > > Content-Encoding: gzip > > Content-Length: 102 > > Content-MD5: 7y85tiUeF/UX9kqpKAzQEw=3D=3D > > Content-Type: text/plain; charset=3Dutf-8 > > Date: Fri, 03 Jan 2014 14:14:27 GMT > > ETag: "7y85tiUeF/UX9kqpKAzQEw=3D=3D" > > Server: CouchDB/1.6.0+build.0bf1856 (Erlang OTP/R16B01) > > > > it will also available in attachments stub info. So before decoding, > > just read content-type value, get att's encoding and decode it > > according it. > > > > -- > > ,,,^..^,,, > > > > > > On Fri, Jan 3, 2014 at 7:43 PM, Daniel Gonzalez > > wrote: > > > No, what I mean is "how can I keep track of the encoding used for eac= h > of > > > the attachments, so that I can decode then correctly whenever I want > to" > > > > > > > > > On Fri, Jan 3, 2014 at 4:23 PM, Alexander Shorin > > wrote: > > > > > >> Not sure if I follow your idea. You mean, that how you can set such > > >> charset info for existed attachments? In this case you have to > > >> reupload them. > > >> -- > > >> ,,,^..^,,, > > >> > > >> > > >> On Fri, Jan 3, 2014 at 6:40 PM, Daniel Gonzalez < > gonvaled@gonvaled.com> > > >> wrote: > > >> > Thanks but, how do you set that on a per-attachment basis in a > couchdb > > >> > document? If this is not supported, I guess I will have to add a > > mapping > > >> > "attachments-encoding" to the document where I can associate each > > >> > attachment with its encoding. Any comments on this? > > >> > > > >> > > > >> > On Fri, Jan 3, 2014 at 3:18 PM, Alexander Shorin > > >> wrote: > > >> > > > >> >> You can set MIME type as text/plain;charset=3Dutf-8 to help brows= ers > > >> >> detect the correct content encoding. > > >> >> See http://tools.ietf.org/html/rfc2068#section-3.4 for more info > > >> >> -- > > >> >> ,,,^..^,,, > > >> >> > > >> >> > > >> >> On Fri, Jan 3, 2014 at 5:52 PM, Daniel Gonzalez < > > gonvaled@gonvaled.com> > > >> >> wrote: > > >> >> > Hi, > > >> >> > > > >> >> > I have the following test script: > > >> >> > > > >> >> > # -*- coding: utf-8 -*- > > >> >> > > > >> >> > import os > > >> >> > import couchdb > > >> >> > > > >> >> > GREEK =3D u'=C1=C2=C3=C4 =C5=C6=C7=C8 =C9=CA=CB=CC =CD=CE=CF=D0= =D1=D3=D4=D5 =D6=D7=D8=D9 =E1=E2=E3=E4 =E5=E6=E7=E8 =E9=EA=EB=EC =ED=EE=EF= =F0 =F1=F2=F4=F5 > > =F6=F7=F8=F9' > > >> >> > > > >> >> > # Prepare a unicode file, encoded using ENCODING > > >> >> > ENCODING =3D 'utf-8' > > >> >> > filename =3D '/tmp/test' > > >> >> > open(filename, 'w').write(GREEK.encode(ENCODING)) > > >> >> > > > >> >> > # Create an empty document > > >> >> > server =3D couchdb.Server() > > >> >> > db =3D server['cdb-tests'] > > >> >> > doc_id =3D 'testing' > > >> >> > doc =3D { } > > >> >> > db[doc_id] =3D doc > > >> >> > > > >> >> > # Attach the file to the document > > >> >> > content =3D open(filename, 'rb') # Open the file for reading > > >> >> > db.put_attachment(doc, content, content_type=3D'text/plain') > > >> >> > > > >> >> > As you can see, the file is utf-8 encoded, but when I attach th= at > > >> file to > > >> >> > couchdb, I have no way to specify this encoding. Thus, requesti= ng > > the > > >> >> > attachment at http://localhost:5984/cdb-tests/testing/testretur= ns > > >> the > > >> >> > following Response Headers: > > >> >> > > > >> >> > HTTP/1.1 200 OK > > >> >> > Server: CouchDB/1.2.0 (Erlang OTP/R15B01) > > >> >> > ETag: "7y85tiUeF/UX9kqpKAzQEw=3D=3D" > > >> >> > Date: Fri, 03 Jan 2014 13:43:36 GMT > > >> >> > Content-Type: text/plain > > >> >> > Content-MD5: 7y85tiUeF/UX9kqpKAzQEw=3D=3D > > >> >> > Content-Length: 102 > > >> >> > Content-Encoding: gzip > > >> >> > Cache-Control: must-revalidate > > >> >> > Accept-Ranges: none > > >> >> > > > >> >> > Seeing the attachment with a browser shows complete gibberish. > How > > >> can I > > >> >> > store the encoding for couchdb attachments? > > >> >> > > > >> >> > Thanks and regards, > > >> >> > > > >> >> > Daniel > > >> >> > > > >> >> > PD: SO reference link: > http://stackoverflow.com/q/20905157/647991 > > >> >> > > >> > > > --047d7b2e4d58cd67f004ef1378ed--