Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save BigBlueHat/626427 to your computer and use it in GitHub Desktop.

Select an option

Save BigBlueHat/626427 to your computer and use it in GitHub Desktop.
# This is a bash script intended for use in a Mac OS X Automator Service script.
# Add the script below in a "Run Shell Script" action set to "/bin/bash" in Automator.
# Known issues (several...) are at the bottom.
# Edit this line to your CouchDB instance and a db you can write to.
couch="http://{replaceme}.couchone.com/{metoo}/"
for f in "$@"
do
filename=${f##*/}
filename="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$filename")"
mimetype=`file "$f" --mime-type`
mimetype=${mimetype##*:}
curl -X PUT --data-binary @$f -H "Content-Type: $mimetype" "$couch/$filename/$filename"
done
# Known Issues / TODO
# 1. Uploading text files works fabulously..binary files, tho, not so much:
# a. You'll get a method_not_allowed error when uploading a binary file, and then a success message
# b. The binary file will be a 0 byte file in CouchDB--*obviously* needs fixing :}
# 2. There's no pretty user output when the action runs, so you'll not know if the files are up without checking your db
# 3. I'd love to add authentication as a user-info request when the script runs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment