You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by Apache Wiki <wi...@apache.org> on 2010/09/14 09:06:07 UTC
[Couchdb Wiki] Update of "Return a document's attachment from inside a vhost and/or redirect" by matiu
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.
The "Return a document's attachment from inside a vhost and/or redirect" page has been changed by matiu.
The comment on this change is: how to serve document attachments from inside of vhosts and rewrites.
http://wiki.apache.org/couchdb/Return%20a%20document%27s%20attachment%20from%20inside%20a%20vhost%20and/or%20redirect
--------------------------------------------------
New page:
= 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 _design/yourname .. but I checked the source and for rewrites that start with '..' at least, they're relative to _design/yourname/_rewrite (or whatever the rewrite thing is called) so to rewrite this rewrite rule works for me so people can see the attachement:
{{{
{
"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.