Estou tendo problemas para fazer o upload de arquivos com mais de 2Mb, usando o express.js , abaixo está mensagem e código do curso:
<pre>PayloadTooLargeError: request entity too large
<br> at readStream (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\raw-body\index.js:155:17)
<br> at getRawBody (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\raw-body\index.js:108:12)
<br> at read (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\body-parser\lib\read.js:77:3)
<br> at urlencodedParser (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\body-parser\lib\types\urlencoded.js:116:5)
<br> at Layer.handle [as handle_request] (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\express\lib\router\layer.js:95:5)
<br> at trim_prefix (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\express\lib\router\index.js:317:13)
<br> at E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\express\lib\router\index.js:284:7
<br> at Function.process_params (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\express\lib\router\index.js:335:12)
<br> at next (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\express\lib\router\index.js:275:10)
<br> at expressInit (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\express\lib\middleware\init.js:40:5)
<br> at Layer.handle [as handle_request] (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\express\lib\router\layer.js:95:5)
<br> at trim_prefix (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\express\lib\router\index.js:317:13)
<br> at E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\express\lib\router\index.js:284:7
<br> at Function.process_params (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\express\lib\router\index.js:335:12)
<br> at next (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\express\lib\router\index.js:275:10)
<br> at query (E:\Estudo\sources\nodejs\alura-nodejs-rest\payfast\node_modules\express\lib\middleware\query.js:45:5)
</pre>
custom-express.js
/**
* use content-type: application/json
*/
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
upload.js
var fs = require('fs');
var _app = null;
module.exports = function (app) {
_app = app;
_app.post("/upload", _upload);
}
function _upload(req, res) {
console.log('receiving image');
var filename = req.headers.filename;
req.pipe(fs.createWriteStream('files/' + filename))
.on('finish',
function () {
res.status(201).send('ok');
});
}