首页 > 解决方案 > 用 JavaScript 读取 PDF 文件并通过 API 发送数据

问题描述

我基本上是在 JS 中寻找与此 Python 代码等效的功能:

它读取 pdf 文件并通过 Post 请求发送字节

from requests import get, post
source = "my_pdf.pdf"

with open(source, "rb") as f:
    data_bytes = f.read()

post_url = "my_url"
resp = post(url = post_url, data = data_bytes)

目前我正在使用 react-jsonschema-form 库,该库具有从以下代码读取/加载文件的选项:

{
  "title": "Files",
  "type": "object",
  "properties": {
    "file": {
      "type": "string",
      "format": "data-url",
      "title": "Single file"
    }

  }
}

上面的 json 模式生成这种形式:

在此处输入图像描述

有了它,我可以从我的计算机加载文件:

在此处输入图像描述

但是从这里开始,我不知道如何将数据发送到 API

标签: javascriptpythonapi

解决方案


推荐阅读