【问题标题】:ng-file-upload times out after 2 minutes even though the uploading is in process in backend即使后端正在上传,ng-file-upload 也会在 2 分钟后超时
【发布时间】:2020-10-29 17:54:57
【问题描述】:

我在 angularjs 中使用 ng-file-upload 时遇到了这个问题。即使后端正在上传(node-js 代码),chrome 也会在 2 分钟后超时并抛出 net::ERR_EMPTY_RESPONSE。我尝试添加超时

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

但它仍然无法正常工作。 API 需要 4-5 分钟才能响应,但调用会在 2 分钟后超时。有人可以帮忙吗?

【问题讨论】:

  • 似乎是 this question 的副本,它也没有答案。如果我是你,我会切换到不同的库或编写自己的上传脚本,如示例here

标签: javascript angularjs google-chrome timeout ng-file-upload


【解决方案1】:

我通过在节点 api 调用中提供请求超时解决了这个问题。

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

我还在我的代码中添加了一个全局超时拦截器。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-28
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    相关资源
    最近更新 更多