node.js - 如何更改 Firebase 中的正文解析器限制?

标签 node.js express firebase google-cloud-functions body-parser

我正在尝试将文件上传代理到 firebase 云函数,以不公开我们的 API url。

似乎 Firebase 在后台使用 Body-parser 来解析请求中的正文,但默认情况下限制为 100kb。

我试过这个: var bodyParser = require('body-parser'); app.use(bodyParser.json({limit: '50mb'})); app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
但似乎它没有使用那个bodyParser。它使用嵌入到 Firebase 框架中的私有(private)版本。有没有办法改变它的限制?

这就是我得到的:

Blockquote error: { Error: request entity too large at readStream (/usr/local/lib/node_modules/firebase-tools/node_modules/raw-body/index.js:196:17) at getRawBody (/usr/local/lib/node_modules/firebase-tools/node_modules/raw-body/index.js:106:12) at read (/usr/local/lib/node_modules/firebase-tools/node_modules/body-parser/lib/read.js:76:3) at urlencodedParser (/usr/local/lib/node_modules/firebase-tools/node_modules/body-parser/lib/types/urlencoded.js:115:5) at Layer.handle [as handle_request] (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:317:13) at /usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:335:12) at next (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:275:10) at textParser (/usr/local/lib/node_modules/firebase-tools/node_modules/body-parser/lib/types/text.js:78:7) at Layer.handle [as handle_request] (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:317:13) at /usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:335:12) at next (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:275:10) at rawParser (/usr/local/lib/node_modules/firebase-tools/node_modules/body-parser/lib/types/raw.js:76:7) expected: 611961, length: 611961, limit: 102400, message: 'request entity too large', status: 413, statusCode: 413, type: 'entity.too.large' } Blockquote

最佳答案

你也用:app.use(express.json()) ?
如果你也使用这个中间件,express.json() 有 100kb 的限制,你应该尝试不使用它。

关于node.js - 如何更改 Firebase 中的正文解析器限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45489810/

相关文章:

node.js - 修改 mongoose pre-validate hook 中的数据

mysql - 无法从我的 App Engine 访问 Google Cloud SQL 数据库

javascript - 带有 iOS Swift 请求超时的 Express.js 服务器

javascript - 当我将图像上传到 firebase 存储并检索下载 url 并显示在 img 标记中但它显示多次时

javascript - 我想在 Node.js : But I have no clue? 上使用 Twit 回复 'target' 推文

javascript - 如何在运行时导入 Vue 组件的 webpack block 时添加授权 header

node.js - 如何使用socket.io从客户端调用服务器端函数?

node.js - 在 ReactJS 上使用 Multer 显示来自 MongoDB 的图像时出现问题

java - 赋予 firebase 数据库名称等于 USER ID 键的子级

Android观察者模式和数据绑定(bind), bool 属性改变时启动 Activity