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...@gmail.com> on 2008/11/16 16:46:26 UTC

Uploading a file from an html form to a CouchDB attachment

I have been puzzling over the best way to upload a file from an HTML
form and have it end up as an attachment to a new CouchDB document.

Here is what I would like to do:

1) User select file using a "file" form element
2) User clicks the submit button
3) New CouchDB doc is created
4) Selected document is POSTed as an attachment to the new CouchDB doc

One snag is the fact that jquery.couch.DB.saveDoc does not not return
the autogenerated doc id, which makes it impossible to generate the
attachment url.

The bigger snag is the chaining of the two POSTs together. Based on my
preliminary Googling It does not appear possible to trigger a file
upload from javascript.

Has anyone tackled this?

- Justin Walgran

Re: Uploading a file from an html form to a CouchDB attachment

Posted by Dean Landolt <de...@deanlandolt.com>.
On Sun, Nov 16, 2008 at 10:46 AM, Justin Walgran <jw...@gmail.com> wrote:

> I have been puzzling over the best way to upload a file from an HTML
> form and have it end up as an attachment to a new CouchDB document.
>
> Here is what I would like to do:
>
> 1) User select file using a "file" form element
> 2) User clicks the submit button
> 3) New CouchDB doc is created
> 4) Selected document is POSTed as an attachment to the new CouchDB doc
>
> One snag is the fact that jquery.couch.DB.saveDoc does not not return
> the autogenerated doc id, which makes it impossible to generate the
> attachment url.
>
> The bigger snag is the chaining of the two POSTs together. Based on my
> preliminary Googling It does not appear possible to trigger a file
> upload from javascript.
>
> Has anyone tackled this?


I believe you have to use an iframe if you want to do it in javascript. This
has definitely been tackled -- take a closer look at Futon -- it's in there.