couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <robert.new...@gmail.com>
Subject Re: deliver attachment in show function?
Date Fri, 28 May 2010 11:10:35 GMT
Attachments aren't available through show functions. JSON and binary
don't place nicely together. What makes it a little more confusing is
that you'll see the _attachments object in your document with
everything *except* the data. :)

B.

On Fri, May 28, 2010 at 11:58 AM, Jan Prieser <j.prieser@hotornot.de> wrote:
> Hi,
>
> is it possible to deliver an attachment through a show function?
> i've tried this with no success:
> GET
> /images/_design/images/_show/onlineimage/a0cbe43b55828d33320cf6cbd40bdb81?attachments=true
>
> function (doc, req) {
>        if (doc.type == "image" && doc.online == "online") {
>                return {
>                        body: doc._attachments["filename"].data,
>                        headers: { "content-type" :
> doc._attachments["filename"].content_type}
>
>                }
>        }
>        else {
>                return 'not found or offline';
>        }
> }
>
> Reason is to rewrite this URL in varnish cache and only deliver images which
> are flagged online in doc.online.
> My application would ask for http://varnish/image/<imagedocid> and only get
> online images.
> I'm trying to avoid an extra http roundtrip through the application server.
>
> any ideas how to accomplish this scenario?
>
> regards,
> jan prieser
>

Mime
View raw message