Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 33642 invoked from network); 19 Apr 2009 12:02:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 Apr 2009 12:02:32 -0000 Received: (qmail 1151 invoked by uid 500); 19 Apr 2009 12:02:30 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 1043 invoked by uid 500); 19 Apr 2009 12:02:30 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 1031 invoked by uid 99); 19 Apr 2009 12:02:30 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Apr 2009 12:02:30 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [83.97.50.139] (HELO jan.prima.de) (83.97.50.139) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Apr 2009 12:02:21 +0000 Received: from [192.168.1.3] (24-181-215-233.dhcp.hckr.nc.charter.com [::ffff:24.181.215.233]) (AUTH: LOGIN jan, SSL: TLSv1/SSLv3,128bits,AES128-SHA) by jan.prima.de with esmtp; Sun, 19 Apr 2009 12:01:56 +0000 Cc: user@couchdb.apache.org Message-Id: <0E06DEA4-4F96-4B85-A632-9789B3FAFD4A@apache.org> From: Jan Lehnardt To: dev@couchdb.apache.org In-Reply-To: Content-Type: text/plain; charset=WINDOWS-1252; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Apple Message framework v930.3) Subject: Re: Creating attachments from HTML's INPUT type="file" Date: Sun, 19 Apr 2009 08:01:53 -0400 References: <1A1A730B-6A6C-4CD6-81B1-58F1D7F4980A@apache.org> X-Mailer: Apple Mail (2.930.3) X-Virus-Checked: Checked by ClamAV on apache.org On 19 Apr 2009, at 05:16, Oliver Boermans wrote: > 2009/4/19 Curt Arnold : >> The only mechanism that seems to provide access to the local =20 >> filesystem is >> HTML's file-select control and does not appear to provide a =20 >> mechanism to >> control the request sent to the action URL so that it could conform =20= >> to the >> CouchDB API. > > Hey Curt, > Have been tackling this problem myself recently. Here are some notes > of what I discovered. If I am wrong or others have better techniques > hopefully they will share them here. Regardless, I hope this helps you > get to the bottom of it more quickly than I did! > > To upload a file from a HTML form to CouchDB (without middleware and > while preserving it=92s mime type ) use a regular form POST to an > _existing_ document. > > Set the name of the file input as _attachments. CouchDB also expects > to receive a matching revision value for modifications to existing > documents. A hidden field named _rev in the same form will do that > providing it has the correct value. > > If the uploaded file name matches an existing attachment of the same > document, the existing file will be replaced. Otherwise the new file > will be appended to that document=92s array of attachments. > > To do this with the guise of an ajax operation (file data cannot be > uploaded with ajax as far as I can tell) I made a small modification > to the jquery.form plugin : > > Replacing: > var ta =3D doc.getElementsByTagName('textarea')[0]; > xhr.responseText =3D ta ? ta.value : =20 > xhr.responseText; > With: > var ta =3D doc.getElementsByTagName('pre')[0]; > xhr.responseText =3D $(ta).text(); > > The plugin loads the server response into a generated iframe while > providing access to the server response. Trouble is it expects the > server to send the json response wrapped in a