Skip to content


Subversion checkout URL

You can clone with
Download ZIP


CouchDB "_attachments" #73

NilsNoreyson opened this Issue · 4 comments

3 participants


The current framework of Lithium seems not he be set to upload "_attachments" to CouchDB.

By using for example the FormHelper the files are not added in the CouchDB database as the, by CouchDB provided, _attachment field. Thi field could in a second step be simply loaded.

Also the by naming the field _attachment has no success since CouchDB does not allow to insert the file by this way.

The current framework makes it impossible to upload files to CouchDB.

Thanks, Nils


please provide some sample code. Looks like we may need to use PUT instead of POST for documents with attachments.


Hi gwoo,
I am working on the Photoblog tutorial in combination with the CouchDB.
The simple examples provided by the CouchDB explains how to insert a file into a existing document. This worked well in our case:

curl -vX PUT http://CouchDB:5984/photoblog/[-ID-OF-DOCUMENT] /Nikki2.jpg?rev=[-CURRENT-REVISION-] --data-binary @/Niki-de-Saint-Phalle3.jpg -H "Content-type:image/jpg"

The new _attachment entry in the document had the same atributes as provided by the Lithium Framework (size, type ...). Only the _attachment is missing when using Lithium.

As you mentioned we tried to use the PUT method, but this didn't help in the simple matter we tried it as seen in the example code below. Nevertheless the entry got still created in CouchDB but still without the picture.

Extraced from the photoblog tutorial /app/views/edit.html.php with some modifications. We are using the current release (yesterday) of lithium.

<?=$this->form->create($photo, array('type' => 'file', 'method' => 'put')); ?>

<?=$this->form->field('title'); ?>
<?=$this->form->field('description'); ?>

<?php if (!$photo->exists()) { ?>
<?=$this->form->field('file', array('type' => 'file', 'method' => 'put')); ?>
<?php } ?>

<?=$this->form->submit('Save'); ?>
<?=$this->form->end(); ?>

Best regards, Nils

@gwoo gwoo was assigned

Probably refs Ticket 391 on "PUT request 'form' data is lost".


We'll need to build an abstraction for handling binary data (MongoDB's gridfs object, CouchDB inline and ref'ed attachments). Otherwise we'll end up duplicating code i.e. MIME-type checking etc. This is a medium large task.

@davidpersson davidpersson modified the milestone: future
@NilsNoreyson NilsNoreyson removed this from the future milestone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.