我正在创建一个使用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...
任何提示,我要去哪里错了?