We have a new wiki. The migration is not 100% complete. You can help out by moving pages across. This wiki will exist for as long as there are pages left.

The official documentation has moved to http://docs.couchdb.org — The transition is not 100% complete, but http://docs.couchdb.org should be seen as having the latest info. In some cases, the wiki still has some more or older info on certain topics inside CouchDB.

You need to be added to the ContributorsGroup to edit the wiki. But don't worry! Just email any Mailing List or grab us on IRC and let us know your user name.

How to Return a document's attachment from inside a vhost and/or redirect

When you're inside of a vhost with rewrites, people can't see the database documents, and also can't see their attachents.

This was really annoying for me as all my product documents have images.

I first tried adding the ?with_attachments (or whatever it is) in a show function, but I thought, whoa! I'm gonna load 5 images into memory (in base64 encoding no less) to just return one .. that's a bit sucky.

So anyway, the docs say that rewrites are relative to /dbname/_design/designname .. I expected ../ in a rewrite to return the '/db/' root, but it actually needs '../../':

    "from":   "/products/dvrs/:doc/:attachment",
    "to":     "../../:doc/:attachment",
    "method": "GET" 

I'm not sure if there are any security issues with serving attachments like this. Technically someone might be able to put anything in :doc and anything in :attachment and they'd be getting it basically from the database root. So I'm going to be putting in another rewrite rule/filter on my nginx to stop them putting '_' in the names.

It'd be neat to have a rewrite customisable rewrite function or filter option.

Return a document's attachment from inside a vhost and/or redirect (last edited 2011-11-23 15:16:41 by JanLehnardt)