client code:
var xhr = new XMLHttpRequest();
xhr.open('POST', '/frame', true);
xhr.send(blob);
server code:
app.use(bodyParser.urlencoded({extended: false,limit: '50mb'}));
app.post('/frame', function (req, resp) {
console.log(req.body);
});
this gives PayloadTooLargeError: too many parameters adding
xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
doesn't solve the problem. Any other ideas?
Assuming your blob variable is not really url encoded form data and just any kind of content. Then at the server side you can just read the request stream as it comes in. Remember that the req
variable on your http.Server.request
event handler is a readable stream. This will remove any size limit imposed by the body-parser
middleware. Keeping your original client code then your server code would be:
// app.use(bodyParser.urlencoded({extended: false,limit: '50mb'}));
app.post('/frame', function (req, resp) {
req.on('readable', function(){
console.log(req.read());
});
});
Processing request as it is streamed in is a good idea even for structured data if the content is too big. For example in the past I had hit performance problems when i use body-parser#json
middleware with big json requests and solve the issue removing the body-parser#json
middleware and using oboe for parsing the streamed input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With