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 >> filesystem is >> HTML's file-select control and does not appear to provide a >> mechanism to >> control the request sent to the action URL so that it could conform >> 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’s 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’s 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 = doc.getElementsByTagName('textarea')[0]; > xhr.responseText = ta ? ta.value : > xhr.responseText; > With: > var ta = doc.getElementsByTagName('pre')[0]; > xhr.responseText = $(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