LoginSignup
1
0

More than 5 years have passed since last update.

Bluemix の Cloudant から、 Node.js の nano で画像ファイルをダウンロード

Posted at

次のページで行うことと同じことを、Node.js の nano を使って行いました。
Bluemix の Cloudant から、 Node.js の cradle で画像ファイルをダウンロード

from_cloudant_nano.js
#! /usr/bin/node
// ---------------------------------------------------------------
//  from_cloudant_nano.js
//
//                  Jul/27/2017
//
// ---------------------------------------------------------------
var fs = require('fs')
// ---------------------------------------------------------------
console.log ("*** 開始 ***")
//
const db_name = 'jpg'

const url="https://44b508dd-f332-4f91-81f2-78369c7d29d9-bluemix:9dacdfde3316c2a5c16596fc371012e08a61e7132d3b21ecaaf1f63a825fae64@efc189dc-f332-4f91-81f2-71259c7d29d9-bluemix.cloudant.com"

var nano = require('nano')(url)
var dbx = nano.use(db_name);

dbx.list(function(err, body)
    {
    if (!err) {
        body.rows.forEach(function(doc)
            {
            console.log(doc.key)
            couchdb_fetch_proc (dbx,doc.key)
            })
        }
    })

console.log ("*** 終了 ***")
// ---------------------------------------------------------------
function couchdb_fetch_proc (dbx,key)
{
    const file_out = key + '.jpg'

    dbx.attachment.get(key, file_out, function(err, body)
        {
        if (!err) {
            fs.writeFile(file_out, body);
            }
        })
}

// ---------------------------------------------------------------
1
0
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
1
0