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

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

问题描述

我使用 express 来处理 post 请求并强大地解析上传的文件:

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:

");
    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 node 8 engine 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

推荐答案

强大不'不使用 Cloud Functions,原因与 multer 不起作用.请改用 busboy.

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

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

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