mattange / loopback-connector-couch

Provides Loopback.io connector for CouchDB document databases.
20 stars 11 forks source link

Sample for attachment handling? #7

Closed Stwissel closed 8 years ago

Stwissel commented 8 years ago

Since it is modeled after nano it should|does (?) handle attachments. Is there an example for it? Or hints how to use

paulJordaan commented 8 years ago

You can access nano from your datasource.

var db = app.dataSources.{yourDatasourceName}.connector._nanoWriter;

You can then use the normal nano attachment functions

 fs.readFile(file.path, function (err, data) {
      if (err){
        console.log(err);
      }else{              
          db.attachment.insert(id,"image",data,'image/png',
          { rev: rev }, function(err,body){
            if (!err) {
              // process
            } else {
              console.log(err);
            }
          });
        }; ` 
  });  
Stwissel commented 8 years ago

Brilliant. Thx for the sample. Would make a good addition to the documentation