You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by slymak <sl...@gmail.com> on 2010/09/17 16:13:41 UTC

upload file via curl

Hello,
I'm new on this mailing list if my question was solved here before please
write me a link there, I didn't find it using search.

I want upload files via bash.
I'm able now select file names and store that as keys
+ insert fields name, date
______________________________________________________________
#!/bin/sh
IDATE=$(date +%Y:%m:%d)

curl -X DELETE http://localhost:5984/test
curl -X PUT    http://localhost:5984/test

for FILE in `ls jcl/*`; do
sfile=`echo $FILE | sed -e 's/jcl\///'`
curl -X PUT http://localhost:5984/test/$sfile -d  '{"name":"'$sfile'",
"date":"'$IDATE'"}'

#"@jcl/"$sfile
done
_____________________________________________________________

how to include attachment into cURL?

my files are in jcl directories should stay for upload here:
/usr/share/couchdb/www/jcl/
?

thank you for advance
Fanda

Re: upload file via curl

Posted by "Mark J. Reed" <ma...@gmail.com>.
On Fri, Sep 17, 2010 at 10:13 AM, slymak <sl...@gmail.com> wrote:
> how to include attachment into cURL?

Once you've created $database/$document, just PUT the contents of the
file you want to attach to
/$database/$document/$attachmentName?rev=$rev, where $rev is the
revision from your newly-created document.  Example:

curl -X DELETE http://localhost:5984/test
curl -X PUT http://localhost:5984/test
(cd jcl
for file in *; do
    rev="$(curl -X PUT http://localhost:5984/test/$file -d '{"name":
"'"$file"'", "date": "'"$IDATE"'" }' | sed -ne
's/^.*"rev":"\([^"]*\)".*$/\1/p')"
    curl --data-binary @"$file"  -X PUT
http://localhost:5984/test/$file/contents?rev="$rev"
done)
-- 
Mark J. Reed <ma...@gmail.com>