S
S
Sp1keazyYT2019-04-14 21:47:50
JavaScript
Sp1keazyYT, 2019-04-14 21:47:50

How to take value from one image2base64 function and transfer it to another constant in Node JS?

Good afternoon. I work with the AntiGate API (AntiCaptcha). There is the following code:

// http module should be installed:
// npm i http

// Params:
// your anti-captcha.com account key
var anticaptcha = require('./anticaptcha')('***');

const image2base64 = require('image-to-base64');
image2base64("https://api.vk.com/captcha.php?sid=405226711931&s=1") // you can also to use url
  .then(
    (response) => {
      console.log(response); //cGF0aC90by9maWxlLmpwZw==
    }
  )
  .catch(
    (error) => {
      console.log(error); //Exepection error....
    }
  )

// check balance first
anticaptcha.getBalance(function (err, balance) {
    if (err) {
        console.error(err);
        return;
    }

    // captcha params can be set here
    anticaptcha.setMinLength(5);

    if (balance > 0) {
        anticaptcha.createImageToTextTask({
                case: true, // or params can be set for every captcha specially
                body: '/9j/4AAQSkZJRgABAQAAAQABAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBkZWZhdWx0IHF1YWxpdHkK/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQkMCwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy/8AAEQgAMgCCAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/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l+0uuI1C8AnA4rbtQMdKKK0mTHYbeHkU9+LLjiiip7DGqo2LwOlFFFAH/9k='
            },
            function (err, taskId) {
                if (err) {
                    console.error(err);
                    return;
                }

                console.log(taskId);

                anticaptcha.getTaskSolution(taskId, function (err, taskSolution) {
                    if (err) {
                        console.error(err);
                        return;
                    }

                    console.log(taskSolution);
                });
            }
        );
    }
});

The image2base64 function encodes the image by reference in Base64 and passes it to the response constant.
How to make it so that the value of this constant is not displayed in the console, but is substituted in the body field on line 34 of the code.
// captcha params can be set here
    anticaptcha.setMinLength(5);

    if (balance > 0) {
        anticaptcha.createImageToTextTask({
                case: true, // or params can be set for every captcha specially
                body: ...

The body field should just contain the Base64 code.
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2019-04-14
@Sp1keazyYT

anticaptcha.getBalance(async function(err, balance) {
  // ...
  const API_URL = 'https://api.vk.com/captcha.php?sid=405226711931&s=1';
  const body = await image2base64(API_URL).catch((error) => console.log(error));
  if (balance > 0) {
    anticaptcha.createImageToTextTask({
      case: true, // or params can be set for every captcha specially
      body
    },
    // ...
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question