如何在 express.js 中限制上传文件的大小 [英] How to limit upload file size in express.js

查看:28
本文介绍了如何在 express.js 中限制上传文件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了这个错误提示

error:request entity too large 

上传30MB左右的视频时,

when uploading a video about 30MB,

这里是设置代码

app.use(express.bodyParser({
    uploadDir:'./Temp',
    maxFieldsSize:'2 * 1024 * 1024 * 1024 ',
}));

不确定如何设置 maxFieldsSize 属性,需要一些帮助!!!

am not sure how to set the maxFieldsSize property, need some help!!!

推荐答案

Express使用connect中间件,可以通过以下方式指定文件上传大小

Express uses connect middleware, you can specify the file upload size by using the following

app.use(express.limit('4M'));

连接限制中间件

这篇关于如何在 express.js 中限制上传文件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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