secret
Created

node request pipe feature is not getting complete PNG file over to nano for attachment.

  • Download Gist
pipe-nano-failure.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
// Using Futon I can attach the image from my local directoy which I create using the code
// this code works and request allows me to create a file image in the doirectory where I run this
// code.
// Test #1
var request = require('request');
var fs = require('fs');
 
request('http://localhost:5984/_utils/image/logo.png').pipe(fs.createWriteStream('download_to_fs.png'));
 
// Test #2 --> Pipe not working with nano -- I only get 2 bytes of the image with this one, it is a bad PNG!
var db = require('nano')('http://localhost:5984/test');
var request = require('request');
 
// {} for empty body as parameter is required but will be piped in
request.get("http://localhost:5984/_utils/image/logo.png").pipe(
db.attachment.insert("piped-in", "piped_in.png", {}, "image/png")
);
 
// Test #3 --> Assumes you have run test #1 from same directory. However, if I use the local file and post using nano... it works. Nano seems to be a-okay with file.
var db = require('nano')('http://localhost:5984/test');
var fs = require('fs');
 
fs.readFile('logos_kronos.png', function(err, data) {
if (!err) {
db.attachment.insert('upload-from-fs', 'upload_from_fs.png', data, 'image/png',
{ }, function(err, body) {
if (!err)
console.log(body);
});
}
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.