1

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 ?

  • 1
    Seems like a duplicate of [this question](https://stackoverflow.com/questions/38001037/ng-file-upload-times-out-after-exactly-120-seconds) which also has no answer. If I were you, I would switch to a different library or write your own upload script like the examples [here](https://stackoverflow.com/questions/18571001/file-upload-using-angularjs) – Display Name is missing Jul 09 '20 at 23:19

1 Answers1

2

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');
});