V
V
vitafon0072019-02-15 16:36:22
Images
vitafon007, 2019-02-15 16:36:22

How to send an image via npm request?

A captcha arrives from vk.com, you need to send it to the captcha service. I
use the npm request module.
I stumbled upon a problem:
the file received via callback differs from the file written using pipe. and the file received through pipe is the only correct one. File via callback contains much more information

request.get({
        url: 'http:\/\/api.vk.com\/captcha.php?sid=239633676097&s=1',
        proxy: 'http://342',
        strictSSL: false,
        headers: {
        'User-Agent': ''
      }
    }, 
    function (err, res, body) {
        if (err) {
        	console.log('ERROR ', err);
        } else {
        	console.log('OK ', res);
        	fs.writeFile('file1.txt',  body, 'ascii', function(){});

        }
    }).pipe(fs.createWriteStream('file2.txt'));

I wanted to make base64 code through callback and send it to the service, but I can get base64 only through pipe.
Please help in one of two directions:
1. What is wrong with body via callback and what should be done with it
2. How to send base64 via pipe directly to the rucaptcha service with a post-request where body is my base64
Thank you very much for responding

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vitafon007, 2019-02-17
@vitafon007

add after link
encoding: null

V
Valery V., 2019-02-17
@OlegOleg1980

Look here , I did loading the image in binary, processing the image and saving the file in binary .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question