You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Justin Walgran <jw...@azavea.com> on 2011/02/16 19:15:43 UTC

Downloading CSV from the browser by POSTing keys to a list?

I have a list function that returns a group of documents as a CSV file.

I am feeding this list function with a view, which I am filtering by
passing an array of keys in a JSON object in the body of a POST
request.

I can POST to the list and get the correct response using curl. So far so good.

Is it possible to trigger this post when a user clicks a 'Download
CSV' link on my html page? I can't use $.post because the data is
returned to a callback and I need the data and headers to go to the
browser.

Googling for this results in suggestions that I add an invisible form
to the DOM and post that, but I don't believe this will POST the JSON
body in the way Couch expects.

Any suggestions on how I can make this work?


Thanks,

Justin

Re: Downloading CSV from the browser by POSTing keys to a list?

Posted by Justin Walgran <jw...@azavea.com>.
Thanks for the idea, Anup.

There are 2 gotchas that I think are un-get-aroundable:

    1) I need to POST a content type of 'application/json' but using a
form will send a content type of 'application/x-www-form-urlencoded'

    2) I am posting key values, not query arguments, so a hidden input
field will not result in the data format I need.

I'm leaning toward writing a small node.js app attached to CouchDB as
a handler which will take the form post and convert it to a more
'couchy' request.

Thanks again,

Justin

On Fri, Feb 18, 2011 at 3:19 AM, Stefan Matheis
<ma...@googlemail.com> wrote:
> Anup, then you're actually testing google's chrome which would execute
> php locally? ;)
>
> On Fri, Feb 18, 2011 at 9:11 AM, Anup Bishnoi <pi...@gmail.com> wrote:
>> in fact there's a jquery plugin for doing this i think
>> try this:
>> http://stackoverflow.com/questions/921037/jquery-table-to-csv-export
>>
>

Re: Downloading CSV from the browser by POSTing keys to a list?

Posted by Stefan Matheis <ma...@googlemail.com>.
Anup, then you're actually testing google's chrome which would execute
php locally? ;)

On Fri, Feb 18, 2011 at 9:11 AM, Anup Bishnoi <pi...@gmail.com> wrote:
> in fact there's a jquery plugin for doing this i think
> try this:
> http://stackoverflow.com/questions/921037/jquery-table-to-csv-export
>

Re: Downloading CSV from the browser by POSTing keys to a list?

Posted by Anup Bishnoi <pi...@gmail.com>.
in fact there's a jquery plugin for doing this i think
try this:
http://stackoverflow.com/questions/921037/jquery-table-to-csv-export

Re: Downloading CSV from the browser by POSTing keys to a list?

Posted by Anup Bishnoi <pi...@gmail.com>.
Just a dart in the dark, but you could possibly post to a hidden iframe in
the page, which would trigger the browser to download the csv if content
type in the response is properly set

On Thu, Feb 17, 2011 at 7:05 PM, Justin Walgran <jw...@azavea.com> wrote:

> Thanks for the reply, Stefan. I was also coming to the conclusion that
> some 'middle tier' code might be required. My team is so close to
> making this a pure couchapp. I would hate to have to break that
> achievement for this edge case.
>
> One last call for an HTTP miracle?  :-)
>
> Thanks again,
>
> Justin
>
> On Thu, Feb 17, 2011 at 3:29 AM, Stefan Matheis
> <ma...@googlemail.com> wrote:
> > Justin,
> >
> > On Wed, Feb 16, 2011 at 7:15 PM, Justin Walgran <jw...@azavea.com>
> wrote:
> >> Any suggestions on how I can make this work?
> >
> > what about an server-side "proxy-script" which accepts http-post
> > params from an html-form, executes your couchdb-request and passes the
> > response back to the browser? of course, an extra piece of work, but i
> > don't think that you could solve this, w/o that
> >
> > Regards
> > Stefan
> >
>

Re: Downloading CSV from the browser by POSTing keys to a list?

Posted by Justin Walgran <jw...@azavea.com>.
Thanks for the reply, Stefan. I was also coming to the conclusion that
some 'middle tier' code might be required. My team is so close to
making this a pure couchapp. I would hate to have to break that
achievement for this edge case.

One last call for an HTTP miracle?  :-)

Thanks again,

Justin

On Thu, Feb 17, 2011 at 3:29 AM, Stefan Matheis
<ma...@googlemail.com> wrote:
> Justin,
>
> On Wed, Feb 16, 2011 at 7:15 PM, Justin Walgran <jw...@azavea.com> wrote:
>> Any suggestions on how I can make this work?
>
> what about an server-side "proxy-script" which accepts http-post
> params from an html-form, executes your couchdb-request and passes the
> response back to the browser? of course, an extra piece of work, but i
> don't think that you could solve this, w/o that
>
> Regards
> Stefan
>

Re: Downloading CSV from the browser by POSTing keys to a list?

Posted by Stefan Matheis <ma...@googlemail.com>.
Justin,

On Wed, Feb 16, 2011 at 7:15 PM, Justin Walgran <jw...@azavea.com> wrote:
> Any suggestions on how I can make this work?

what about an server-side "proxy-script" which accepts http-post
params from an html-form, executes your couchdb-request and passes the
response back to the browser? of course, an extra piece of work, but i
don't think that you could solve this, w/o that

Regards
Stefan