javascript - Node js 请求实体太大且有多个上传

标签 javascript node.js

好吧,我已经尝试了不同的方式来上传一个 200k 的文件,增加了限制,改变了参数,做了我改变 multer 的一切。 Fucei 我知道我在堆栈中阅读的所有内容,这是我在谷歌上发现的,基本的谷歌搜索已经完成了我的问题,而不是向上但向下图片就像一个魅力。服务器支持上传图像 我 atualemente 用 php 做这个任务,但如果不在 nodejs 中滚动,我会在 php 中做同样的文件。感谢收听。

我的代码

var express = require('express');
var app = express();
var http = require('http').Server(app);
var bodyParser = require("body-parser");
var fs = require('fs');
var multer = require('multer');



var destino = '/var/www/upload/';
var upload = multer({dest: 'uploads/',
    rename: function (fieldname, filename) {
        return  filename + Date.now();
    },
    limits: {
        fieldNameSize: 200,
        files: 5,
        fields: 5
    }
});

app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());




app.post('/image', upload.single('message'), function (req, res) {


    var file = req.file;
    fs = require('fs')
    fs.readFile(file.path, 'base64', function (err, data) {
        if (err) {
            return console.log(err);
        }

/* do something if data*/
        fs.unlinkSync(file.path);
    });

    });

http.listen(8080, function () {
    console.log("Conectado e escutando na porta: 8080");


});

错误告诉我是这样的:错误:请求实体太大

        at readStream (/var/www/likeyounode/node_modules/body-parser/node_modules/raw-body/index.js:196:17) 
        at getRawBody (/var/www/likeyounode/node_modules/body-parser/node_modules/raw-body/index.js:106:12) 
        at read (/var/www/likeyounode/node_modules/body-parser/lib/read.js:76:3) 
        at urlencodedParser (/var/www/likeyounode/node_modules/body-parser/lib/types/urlencoded.js:109:5) 
        at Layer.handle [as handle_request] (/var/www/likeyounode/node_modules/express/lib/router/layer.js:95:5) 
        at trim_prefix (/var/www/likeyounode/node_modules/express/lib/router/index.js:312:13)
        at /var/www/likeyounode/node_modules/express/lib/router/index.js:280:7
        at Function.process_params (/var/www/likeyounode/node_modules/express/lib/router/index.js:330:12)
        at next (/var/www/likeyounode/node_modules/express/lib/router/index.js:271:10)
        at expressInit (/var/www/likeyounode/node_modules/express/lib/middleware/init.js:33:5)

我检查了我所有的代码,只需要足够多的证据来展示我想要的东西,而不是揭示我的项目的大部分内容。

正文中有一些配置是我做的,如果您注意到它们在内容中有说明,那么怀疑您运行自己的应用程序时不会拥有所有功能。

最佳答案

在我的例子中,设置限制后@node.js (webapp)

var express = require('express'); var app = express(); 
var bodyParser = require('body-parser');            
app.use(bodyParser.json({limit:'50mb'})); 
app.use(bodyParser.urlencoded({extended:true, limit:'50mb'})); 

我还(最重要的)必须设置限制@nginx(webapp反向代理)

 # Max upload size.
client_max_body_size 50M;

关于javascript - Node js 请求实体太大且有多个上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36485333/

相关文章:

javascript - meteor : Not being able to hide UI elements

javascript - 远程javascript页面加载 block

javascript - React 变量发生变化,但没有渲染...为什么?

javascript - 检查 'number' html 表单输入的值并仅在高于 0 时才验证

javascript - 使用外部 Node 脚本连接到已在index.js中定义的socket-io

javascript - 将 Buffer 转换为自定义基础的最佳方法是什么?

javascript - 使用 jquery 旋转后其他元素的不当行为

javascript - Bootstrap 4 Popper.js : How to dynamically update the content of the popup?

Node.js + Socket.io 内存泄漏和最大监听器

javascript - 如何获取值[对象][对象]