Node.js-使用axios调用OCR空间api

问题描述 投票:0回答:1

我正在创建一个使用ocr空间api从上传的图像中检索文本的应用程序。我使用邮递员测试了api,并使用api调用的请求库还测试了Node.js的生成代码段。由于不赞成使用请求模块,我想使用axios来执行我的api调用,但是我仍然失败。到目前为止,这是我的编码。为了处理过帐请求中的文件上传,我使用的是表单数据模块。

const axios = require('axios');
const formData = require('form-data');
const form = new formData();

const stream = fs.createReadStream('path-to-my-file');
form.append('file', stream);
form.append('language', 'eng');
form.append('filetype', 'png');

let url = 'https://api.ocr.space/parse/image'
let options = {
    headers: {
        'apikey': 'my-api-key'
      }
};

axios.post(url, form, options)
      .then(function (response.data) {
          console.log(response);
      }).catch(function (error) {
          console.error(error);
    });

运行此代码将导致以下错误:

OCRExitCode: 99,
  IsErroredOnProcessing: true,
  ErrorMessage: [
    "Parameter name '----------------------------218784067201800707615554\r\n" +
      "Content-Disposition: form-data; name' is invalid. Valid parameters: apikey,url,language,isoverlayrequired...

任何提示,我要去哪里错了?

node.js axios form-data ocrspace-ocr-api
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.