Firebase托管和云功能不适用于强大功能:incomingForm不是构造函数 [英] Firebase hosting and cloud functions don't work with formidable: incomingForm is not a constructor

查看:110
本文介绍了Firebase托管和云功能不适用于强大功能:incomingForm不是构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用express处理帖子请求,并且解析上传的文件非常困难:

I use express to handle post requests and formidable to parse uploaded files:

import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
import * as formidable from "formidable";
import * as util from "util";
import * as express from "express";

admin.initializeApp();
const app = express();

app.post("/image", (req, res) => {
  const form = new formidable.incomingForm();
  form.parse(req, async function(err, fields, files) {
    res.writeHead(200, { "content-type": "text/plain" });
    res.write("received upload:\n\n");
    res.end(util.inspect({ fields: fields, files: files }));
  });
});

export const api = functions.https.onRequest(app);

我已经在firebase.json中重写了源代码和函数.部署和投放服务时,我不断收到错误Internal Server Error:发布表单后,出现TypeError: formidable.incomingForm is not a constructor.

I already rewrite source and function in firebase.json. I kept getting error Internal Server Error when deploying and when serving: TypeError: formidable.incomingForm is not a constructor after posting my form.

formidable与我的计算机上的普通节点服务器和Express服务器一起使用时效果很好.我已经尝试过Firebase节点8引擎beta,使用JS代替TS,但仍然无法正常工作.如何使用Firebase托管和云功能进行强大的工作?请帮忙.

formidable works well with normal node server and Express server on my machine. I already tried firebase node 8 engine beta, used JS instead of TS and still didn't work. How can I make formidable work with Firebase hosting and cloud function? Please help.

这是我简单的客户表格:

Here are my simple client form:

<form action="http://myfirebaseserver/image" method="post" encType="multipart/form-data">
  <input type="file" name="myImage" />
  <button type="submit">Upload</button>
</form>

目前,我正在尝试busboy替代方法,但仍在formidable

At the moment I'm trying busboy for alternative but still looking for solutions on formidable

推荐答案

Formidable不会"不能与Cloud Functions 一起使用,原因与

Formidable doesn't work with Cloud Functions, for the same reason that multer doesn't work. Use busboy instead.

这篇关于Firebase托管和云功能不适用于强大功能:incomingForm不是构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆