Created
October 27, 2015 13:55
-
-
Save hellboy81/06eb32ccb3d9a4bd7a6c to your computer and use it in GitHub Desktop.
Piping to CouchDB Attachment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file is input ReadStream that should be saved to CouchDB attachment | |
// See description: http://git.io/vWMZ9 | |
// See API : http://docs.couchdb.org/en/1.6.1/api/document/attachments.html#put--db-docid-attname | |
var attachment = db.attachment.insert('new', 'rab.png', null, 'image/png', { rev: '12-150985a725ec88be471921a54ce91452' }) | |
// Handle file reading error | |
file.on('error', function (err) { | |
return cb(err) | |
}) | |
// Handle attachment writting error | |
// Lost connection with CoucDB ??? | |
attachment.on('error', function (err) { | |
return cb(err) | |
}) | |
// As in [Professional Node.js](https://goo.gl/ijN1js) written | |
// Client should get response in on('end') event for attachment | |
// Isn't it? | |
attachment.on('end', function () { | |
return cb() | |
}) | |
file.pipe(attachment) |
Author
hellboy81
commented
Oct 27, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment