首页 > 解决方案 > HTTP 文件上传无法解析表单数据?

问题描述

我正在尝试pdf使用html表单将密码上传到我的cloud function,但是在从请求正文中解析两者时返回未识别的错误。

这是 HTML:

<!DOCTYPE html>
<html>
<body>
<!-- curretly using emulator but the error is same if deployed-->
  <form action="http://localhost:5000/ecutter-web/us-central1/test" method="post" enctype="multipart/form-data">
    <input type="file" name="sfile" accept=".pdf">
    <input type="text" name="spass">
    <input type="submit">
  </form>
</body>
</html> 

如果我将它与 body `res.send(req.body) 一起发送回来,这就是 res 的外观:

-----------------------------1282136010350931161350789983 Content-Disposition: form-data; name="sfile"; filename="Aad.pdf" Content-Type: application/pdf %PDF-1.4 ..(returned as text here).. -----------------------------1282136010350931161350789983 Content-Disposition: form-data; name="spass" PDF12345 -----------------------------1282136010350931161350789983--

但是当我尝试使用解析它们中的一个req.body.sfilereq.body.spass它返回未定义时

为什么 ?

标签: javascripthtmlnode.jsfirebasegoogle-cloud-functions

解决方案


推荐阅读