Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
How to return body in REQUEST nodejs

I just want to return a body but I get only {} instead real data.

const Ocr = (file,req,response) => {

    const options = {
        method: "POST",
        url: "https://api.aiforthai.in.th/ocr",
        headers: {
            "Apikey": "LgArg8PNY2BiY1cmtFsE1XXN6bP6O903",
            "Content-Type": "multipart/form-data"
        },
        formData: {
            "uploadfile": fs.createReadStream(file)
        }
    };

    request(options, function (err, res, body) {
        if (err) {
            console.log(err)
            return 
        }
        return body //here I want to return
    });

};

And this is my main function that call the top code.

exports.testOcr = async (req, res, next) => {
    try {
        const file = "docs/uploadsNotice/65/กรุงเทพ.jpg"
        const result = await requestOcr.Ocr(file)
        return res.status(200).json({
            data: result,
        });
    } catch (error) {
        next(error);
    }
};

My function is not returning body

Can someone please help me with this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Are you sure you are using json body-parser as a middle-ware, if not, there won't be a body on req.body.

you can install body-parser via npm: npm install body-parser

and then use the middle-ware as shown below:


    const bodyParser = require("body-parser");
    app.use(bodyParser.json())

for more information check the official express docs here.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda