LoginSignup
2
1

More than 5 years have passed since last update.

複数のファイルをワンライナーでCloudantのAttachmentsへ一括登録する

Last updated at Posted at 2018-09-03

Cloudantを使っていると、ディレクトリにある全てのファイルを一括登録したくなるときがあります。
IBM Cloudantにファイルを一括で登録したくなるときがありますが、CloudantのUIだと1つずつしか登録できない。。。
しかたないのでシェルのワンライナーで実現しましょう。

# 最後のBASIC=user_name:passwordにBASIC認証のパスワードを入力する
# DOC_URL=https://your_cloudant-bluemix.com/your_db/your_document/にdocumentのURLを入力する
$ ls | xargs -L1 -I{} echo 'echo "File:{}" && curl -u $BASIC -sS "$DOC_URL" | jq -r ._rev | tr -d \\r\\n | xargs -L1 -I__rev curl -u $BASIC -XPUT --url "$DOC_URL"'{}?rev=__rev' --data-binary @{}' | BASIC=user_name:password DOC_URL=https://your_cloudant-bluemix.com/your_db/your_document/ bash

どんなに多いファイルでも、Cloudantへのデータ登録は1行で。そう、シェル芸ならね。

ファイル名を表示しつつ、ファイルをアップしてくれます。
また、単一のattachmentsファイルの最大サイズは10MBまでなので、ファイルサイズには気をつけましょう。

output.gif

参考

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1