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 7F6E21090A for ; Fri, 3 Jan 2014 15:49:11 +0000 (UTC) Received: (qmail 92158 invoked by uid 500); 3 Jan 2014 15:49:08 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 92121 invoked by uid 500); 3 Jan 2014 15:49:06 -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 92086 invoked by uid 99); 3 Jan 2014 15:49:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Jan 2014 15:49:05 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of kxepal@gmail.com designates 74.125.82.42 as permitted sender) Received: from [74.125.82.42] (HELO mail-wg0-f42.google.com) (74.125.82.42) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Jan 2014 15:48:59 +0000 Received: by mail-wg0-f42.google.com with SMTP id a1so541639wgh.3 for ; Fri, 03 Jan 2014 07:48:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=sWNyqJbU9JLVP+yCQI6ftOeF6oEPqmL9bywjFgkbnsI=; b=KRyyNuNr0FYZpabp46sIj21l2q5qYP80dV/kG6yD5w9my60xO/aj+QuRzZG6EtCQ2B fPNd+dPtEktZSoghK/05Xh1dR5LlJRQEwU46CL+Ivfvj43vHqtOWL//ki6IM/qrdV13s j7k9kC0ZLz8CICM7kD2x36GvdlGtIFSqtpaKAfJL9cQSLK0NqN4ryQfok7YCu6fYS+Gr AbdIRLdOYpewdaPVsKiKhTQ00/Q5x33dHJ/cYu2TfoUcFNE37jSuky3OJvjon0FXokuK LFsI0iVvDXHSJt8y8MjssK/SGcF55h0SBL24uPRcyNtGuN+FlTdAFdDPVi9Y/vPwCHC/ zCrA== MIME-Version: 1.0 X-Received: by 10.180.12.146 with SMTP id y18mr2401686wib.37.1388764119340; Fri, 03 Jan 2014 07:48:39 -0800 (PST) Received: by 10.180.77.233 with HTTP; Fri, 3 Jan 2014 07:48:39 -0800 (PST) In-Reply-To: References: Date: Fri, 3 Jan 2014 19:48:39 +0400 Message-ID: Subject: Re: Specify attachment encoding for couchdb From: Alexander Shorin To: "user@couchdb.apache.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org 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 wro= te: > No, what I mean is "how can I keep track of the encoding used for each 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 >> 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 mappi= ng >> > "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 browsers >> >> 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 >> >> wrote: >> >> > Hi, >> >> > >> >> > I have the following test script: >> >> > >> >> > # -*- coding: utf-8 -*- >> >> > >> >> > import os >> >> > import couchdb >> >> > >> >> > GREEK =3D u'=CE=91=CE=92=CE=93=CE=94 =CE=95=CE=96=CE=97=CE=98 =CE= =99=CE=9A=CE=9B=CE=9C =CE=9D=CE=9E=CE=9F=CE=A0 =CE=A1=CE=A3=CE=A4=CE=A5 =CE= =A6=CE=A7=CE=A8=CE=A9 =CE=B1=CE=B2=CE=B3=CE=B4 =CE=B5=CE=B6=CE=B7=CE=B8 =CE= =B9=CE=BA=CE=BB=CE=BC =CE=BD=CE=BE=CE=BF=CF=80 =CF=81=CF=82=CF=84=CF=85 =CF= =86=CF=87=CF=88=CF=89' >> >> > >> >> > # 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 that >> file to >> >> > couchdb, I have no way to specify this encoding. Thus, requesting t= he >> >> > attachment at http://localhost:5984/cdb-tests/testing/test returns >> 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 >> >> >>