There's no need to create an empty document first, you can just PUT directly to the attachment url (without a _rev value) and an empty document is made automatically;
curl -XPUT http://host:port/db/doc/att -T <filename> http://wiki.apache.org/couchdb/HTTP_Document_API#Standalone_Attachments B. On 25 February 2013 08:48, Simon Metson <[email protected]> wrote: > Hey, > Yup, base64 encode the attachment and include it in the POSTed document: > > { > "_attachments": > { > "myphoto.png": > { > "content_type":"image\/png", > "data": > "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAABiElEQVQYlQXBzUvbYAAH4N/7sYQkbRpTjGuJzDK/0INYd9hB8Dhhh8EY7DDYceexm7D9CWMH6al3T571IMomePDshlWY7TZs2mLatGls35rk3fOQyNn68mgwKX79sD3a0TX6bbGAo/MzHGSe4I3npdW906yVmTrkakd8HL3btHcK03idtbBWKmLW3sZqL8LYUGBhChAT0NDV/aprAlQRbxdmY0PlsZ0x4lfzbmzOuaI1ZwIPg5BWXqzTT4TgpeWwnELZVe2S3TT+sLDfZ0EsWVRyAHQo/ew4BIaNZ7IH0W2i43fBOUPt1wXuhCBJ0QbQBi+PfPi6ju/9IfzCPDZXTNgsgaYqcINUyl4EAOB3po6kdYMfMwtkVTKiC4HBMJBM19AgkuxuLOF57j04OE3SeAAwK5mEkaxPRkjugX/tFo77URLkDVZZL6cchGa9pyU4rWtlX2M4N1SUrQx+Dw0E1ye8lF8Gv480TsbjGoiKiHVDK/DYzwdHXvz1MEMS5B4X0nqvk0dw2/wPAziepZ5qttMAAAAASUVORK5CYII=" > } > } > } > > > > curl -X POST -d @foo.json -H "Content-Type:application/json" > http://localhost:5984/a1 > > That'll make the doc and it'll have the attachment from the first revision. > Cheers > Simon > > > On Monday, 25 February 2013 at 09:45, Daniel Gonzalez wrote: > >> Hi, >> >> This is what I am currently doing: >> >> 1. Create empty doc >> 2. Get document, to get the _rev >> 3. Put the attachment to the doc >> >> Is is possible to simplify this, and create the empty doc with attachment >> in one go? >> >> Thanks, >> Daniel > > >
