You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用JavaScript POST请求OCR.space API遇Error 99:文件类型识别失败

解决OCR.space API文件类型识别错误的方案

错误提示明确要求手动指定文件类型,只需在请求参数中添加filetype字段即可解决问题:

修改后的OCR函数

async function OCR(jpg) {
  const url = 'https://api.ocr.space/parse/image';
  const data = {
    apikey: 'SECRET',
    base64Image: jpg,
    filetype: 'jpg' // 新增:明确指定文件类型为JPG
  };
  const options = {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(data),
  };

  try {
    const response = await fetch(url, options);
    const json = await response.json();
    return json;
  } catch (error) {
    console.error(error);
    return { error: true };
  }
}

补充说明

你的toBase64函数返回的带data:image/jpeg;base64,前缀的Base64字符串是符合API要求的,无需额外处理前缀。添加filetype参数后,API就能准确识别文件格式,消除E216错误。

内容的提问来源于stack exchange,提问作者Marley Lamparter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 15:46:07