Link to home
Start Free TrialLog in
Avatar of Provost
Provost

asked on

How to put base64 stream in a variable

I have right now the result of the basae64 encoding in the stdout
(response.pipe(new Base64Encode()).pipe(process.stdout);)

I'm looking how to put this result in the variable "base64"




const request = require('request');
const unirest = require('unirest');
var {
    Base64Encode
} = require('base64-stream');


process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;


var theimg = request.get('https://127.0.0.1/cgi-bin/snapshot.cgi?channel=1', {
        'auth': {
            'user': 'Username',
            'pass': 'Password',
            'sendImmediately': false
        }
    },
    function (error, response, body) {
        if (error) {
            return console.error('failed:', error);
        }
    }).on('response', function (response) {
    //console.log(response.statusCode) // 200
    //console.log(response.headers['content-type']) // 'image/png'


    var base64;


    if (response.statusCode == 200) {
        response.pipe(new Base64Encode()).pipe(process.stdout);
    }


    /*unirest.post("https://example.com/api/1/upload/?key=123456789abcd")
        .header('Accept', 'application/json')
        .send({
            source: base64,
            format: 'txt'
        })
        .end(function (response) {
            console.log("IMG:" + response.body);
        })*/
});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial