I don't have the code in front of me, so someone please correct me if I'm wrong, but I recall that CouchDb does not take any notice of part headers in multipart messages. This means that you cannot currently set encoding on a per-attachment basis. (I haven't looked closely at the code to add an attachment to an existing document - does anyone know if you can set the encoding in that case? It doesn't feel likely to me.)
Nick On 3 January 2014 14:40, Daniel Gonzalez <[email protected]> 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 <[email protected]> wrote: > > > You can set MIME type as text/plain;charset=utf-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 <[email protected]> > > wrote: > > > Hi, > > > > > > I have the following test script: > > > > > > # -*- coding: utf-8 -*- > > > > > > import os > > > import couchdb > > > > > > GREEK = u'ΑΒΓΔ ΕΖΗΘ ΙΚΛΜ ΝΞΟΠ ΡΣΤΥ ΦΧΨΩ αβγδ εζηθ ικλμ νξοπ ρςτυ φχψω' > > > > > > # Prepare a unicode file, encoded using ENCODING > > > ENCODING = 'utf-8' > > > filename = '/tmp/test' > > > open(filename, 'w').write(GREEK.encode(ENCODING)) > > > > > > # Create an empty document > > > server = couchdb.Server() > > > db = server['cdb-tests'] > > > doc_id = 'testing' > > > doc = { } > > > db[doc_id] = doc > > > > > > # Attach the file to the document > > > content = open(filename, 'rb') # Open the file for reading > > > db.put_attachment(doc, content, content_type='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 the > > > 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==" > > > Date: Fri, 03 Jan 2014 13:43:36 GMT > > > Content-Type: text/plain > > > Content-MD5: 7y85tiUeF/UX9kqpKAzQEw== > > > 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 > > >
