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
