Search code examples
javascriptangularjsgoogle-chrometimeoutng-file-upload

ng-file-upload times out after 2 minutes even though the uploading is in process in backend


I am facing the issue while using ng-file-upload in angularjs. Even though the uploading is in process in backend (node-js code), chrome times out after 2 minutes and throws net::ERR_EMPTY_RESPONSE. I tried adding timeout

Upload.upload({
     url: uploadFileAPI,
     fields: uploadjson,
     file: file,
     timeout: 600000
})

but it's still not working. The API takes 4-5 mins to respond, but the call times out after 2 minutes. Can anyone please help ?


Solution

  • I solved this issue by providing a request timeout in the node api call.

    uploadFileAPI : function(req, res, next) {          
            var form = new multiparty.Form();
            req.setTimeout(1800000); 
           // ...
    }
    

    I also added a global timeout interceptor to my code.

    app.factory('timeoutHttpIntercept', function($rootScope, $q) {
        return {
            'request': function(config) {
                config.timeout = 1800000;
                return config;
            }
        }
    })
    .config(function($httpProvider) {
        $httpProvider.interceptors.push('timeoutHttpIntercept');
    });