add attachment using cURL

1,186 views
Skip to first unread message

will

unread,
Sep 1, 2010, 7:39:59 AM9/1/10
to CouchApp
G'day again,

I hope everyone is well. I have a follow-up question from the (new
Draft, now) of the "CouchDB Book"

* http://guide.couchdb.org/draft/index.html
-- core api: http://guide.couchdb.org/draft/api.html

There's a simple example to attach a JPEG to a couch document (guid-s
matching my db):

curl -vX
PUT http://127.0.0.1:5984/albums/70b50bfa0a4b3aed1f8aff9e92dc16a0/
artwork.jpg?rev=1-d789a27476ed3962a24736e4138ff71f
--data-binary @artwork.jpg -H "Content-Type: image/jpg"

I am using cURL from a Windows cmd line shell, Windows/XP.

Given the issue with quotes(") last time, I tried a few obvious
permutations with "\"@artwork.jpg\"" and others. There is a file
artwork.jpg in my current directory.

* see: http://groups.google.com/group/couchapp/browse_thread/thread/b70efe75f7bca553

I get an error from the couchDB server:

-- * Could not resolve host: artwork.jpg; Host not found

I also tried full path names and such.

I'm stumped now. Any ideas?

Thanks in advance,

Will.

#############
cURL output

* About to connect() to 127.0.0.1 port 5984 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 5984 (#0)
> PUT /albums/70b50bfa0a4b3aed1f8aff9e92dc16a0/ HTTP/1.1
> User-Agent: curl/7.16.4 (i686-pc-mingw32) libcurl/7.16.4 zlib/1.2.3
> Host: 127.0.0.1:5984
> Accept: */*
> "Content-Type: image/jpg"
> Content-Length: 14
> Content-Type: application/x-www-form-urlencoded

* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server
* Could not resolve host: artwork.jpg; Host not found
* Closing connection #1
curl: (6) Could not resolve host: artwork.jpg; Host not found
* Closing connection #0

#############

Dave Cottlehuber

unread,
Sep 11, 2010, 7:39:06 PM9/11/10
to couc...@googlegroups.com
On 1 September 2010 23:39, will <william....@gmail.com> wrote:
> G'day again,

Hi Will

Curl (not CouchDB) is picking up artwork.jpg as a hostname. The clue
is in the PUT /albums/70b50bfa0a4b3aed1f8aff9e92dc16a0/
which should include the rev=... in a single line.

You probably have a space in between the doc & the attachment.

It works fine for me using following syntax, no quotes needed, which
barring whitespace seems to be exactly the same as yours.

thanks
Dave

C:\>curl -X GET
http://akai.muse.net.nz:5984/dumpy/dee941d577e31aa8e4ac34378700070e
{"_id":"dee941d577e31aa8e4ac34378700070e","_rev":"3-bf96dfa4770e3dbd2226c25baf007c92","camp":"couch","field":"hay","animal":"raccoon"}

C:\>curl -vX PUT
http://akai.muse.net.nz:5984/dumpy/dee941d577e31aa8e4ac34378700070e/attachment?rev=3-bf96dfa4770e3dbd2226c25baf007c92
--data-binary @D:\notes\curl_manual.txt -H "Content-Type: text/plain"
* About to connect() to akai.muse.net.nz port 5984 (#0)
*   Trying 10.224.26.139... connected
* Connected to akai.muse.net.nz (127.0.0.1) port 5984 (#0)
> PUT /dumpy/dee941d577e31aa8e4ac34378700070e/attachment?rev=3-bf96dfa4770e3dbd2226c25baf007c92 HTTP/1.1
> User-Agent: curl/7.19.0 (i586-pc-mingw32msvc) libcurl/7.19.0 OpenSSL/1.0.0a zlib/1.2.3
> Host: akai.muse.net.nz:5984
> Accept: */*
> Content-Type: text/plain
> Content-Length: 126632
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 201 Created
< Server: CouchDB/1.0.1 (Erlang OTP/R14B)
< Location: http://akai.muse.net.nz:5984/dumpy/dee941d577e31aa8e4ac34378700070e/attachment
< Etag: "4-2e84cffafa28e51e59c7d1a8393d24c9"
< Date: Sat, 11 Sep 2010 22:07:41 GMT
< Content-Type: text/plain;charset=utf-8
< Content-Length: 95
< Cache-Control: must-revalidate
<
{"ok":true,"id":"dee941d577e31aa8e4ac34378700070e","rev":"4-2e84cffafa28e51e59c7d1a8393d24c9"}
* Connection #0 to host akai.muse.net.nz left intact
* Closing connection #0

C:\>curl -X GET
http://akai.muse.net.nz:5984/dumpy/dee941d577e31aa8e4ac34378700070e
{"_id":"dee941d577e31aa8e4ac34378700070e","_rev":"4-2e84cffafa28e51e59c7d1a8393d24c9","camp":"couch","barbecue":"awesome
","animal":"raccoon","_attachments":{"attachment":{"content_type":"text/plain","revpos":4,"length":126632,"stub":true}}}

will

unread,
Sep 12, 2010, 12:27:26 AM9/12/10
to CouchApp
That's fixed it up.

I think I've got a JSON question now too. Subsequent attachments are
stored as a list. I might have expected the _attachments field to be
more like an array. Are there options on how '_attachments' are kept?

For example; what if my attachments were in another couchdb table? Is
that possible in the base couchdb or is that some higher-level
function.

Thanks,

Will

On Sep 12, 9:39 am, Dave Cottlehuber <d...@muse.net.nz> wrote:
> On 1 September 2010 23:39, will <william.full.m...@gmail.com> wrote:
>
> > G'day again,
> >   curl -vX
> >       PUThttp://127.0.0.1:5984/albums/70b50bfa0a4b3aed1f8aff9e92dc16a0/
> >       artwork.jpg?rev=1-d789a27476ed3962a24736e4138ff71f
> >       --data-binary @artwork.jpg -H "Content-Type: image/jpg"
>
> .. .. ..
>
> > #############
>
> Hi Will
>
> Curl (not CouchDB) is picking up artwork.jpg as a hostname. The clue
> is in the PUT /albums/70b50bfa0a4b3aed1f8aff9e92dc16a0/
> which should include the rev=... in a single line.
>
> curl -vX
> PUThttp://127.0.0.1:5984/albums/70b50bfa0a4b3aed1f8aff9e92dc16a0/artwork...

Dave Cottlehuber

unread,
Sep 13, 2010, 4:12:17 AM9/13/10
to couc...@googlegroups.com
Hi Will

Couch has no table concept. Attachments aren't stored in tables, as
they are a key/value property of a doc.

What can't you do, that makes you think of handling _attachments differently.

NB these questions aren't couchapp ones, better sent to user@ in future.

cheers
Dave

> --
> You received this message because you are subscribed to the Google Groups "CouchApp" group.
> To post to this group, send email to couc...@googlegroups.com.
> To unsubscribe from this group, send email to couchapp+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/couchapp?hl=en.
>
>

will

unread,
Sep 13, 2010, 12:17:27 PM9/13/10
to CouchApp
Hi Dave,

That's fair -- I was only asking. I didn't know where to ask Couch-
Rest questions. Or just baseline couchdb queries.

When I looked to a couchdb list, the direction I recall was to post to
couchapp. I'd like to post questions to the best place for me to get
newbie answers? Is there a couchdb start-er list?

On the other hand, I like to get a basic understanding on how
something so critical and central like CouchDB works before I accept
the presentations of a superordinate-layer like couchapp. In software
above all things, the API {map} is not the customer-value-
proposition{territory}.

My secondary motivation is to get an idea of how CouchApp fits with
CouchDB. I accept that kind of though/question is somewhat esoteric.
If you can point me to a couchdb discussion, that's good.

Thanks for the assist.

w.

Nathan Stott

unread,
Sep 13, 2010, 12:49:51 PM9/13/10
to couc...@googlegroups.com
Couchapp is a way of creating design documents for couchdb. The best
place to learn about couchdb is on the wiki.
http://wiki.apache.org/couchdb/

Reply all
Reply to author
Forward
0 new messages