Tuesday 16 May 2017

Node js - How to send request into small chunk of data (Error: request entity too large)

Every time I am trying to send a huge Json object(contains images base64) over the network to my node js server.I get this

Error: request entity too large

There is solution like this link (stackoverflow question) that recommend to increase the limit on the node js server. I am looking for a client side solution. Is there any way to break down the data sent and have the server wait to receive all the packets and then process? (promise??)

Hypothetically speaking, if my files is 20mb, even if my limit is set to 5mb, I will be able to send it, it will just take more time. Is it possible? Can you please put me on the right track?

I am using express on the back end side

Here some code to refer:

    //AJAX CALL
    var promise = $.Deferred();
    $.ajax('/module/report/ddl',{
        data: {
            widget: JSON.stringify(widget), <--- large, very large
            filename: filename,
            username: username,
            reportname: reportName
        },
        type: 'POST',
        success: function(result){
            //Do something
            promise.resolve(result);
        },
        error :function(err) {
            /* Act on the event */
            promise.reject(err);
        }
    });
    return promise;
}

Here is my server side

   router.route('/ddl').post(ddlReport));
   function ddlReport(req, res){
     var filename = req.body.filename;
     var widgets = req.body.widget; <--- Once again large
     var username = req.body.username;


ctrl.ddlProcess(widgets,filename,title,username,function(err, result){
    if(err){
        res.status(422).send(err);
    }else {
        res.send(result);
    }
});

}

If you need anymore information, let me know! I am trying to find a solution that would be best even if it is not the one that I suggested!

Thank you for your time! Have good day!



via TheOneWhoMightKnow

No comments:

Post a Comment