上传大文件时angularjs请求超时

t3irkdon  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(320)

我上传了一个大文件要在服务器上处理使用angularjs前端。上传文件后,我看到一个预览的处理文件。当我点击确认按钮发出第二个请求时,chrome网络日志中出现以下错误,服务器没有收到请求。
(失败)net::err\u connection\u reset
版本java:-1.8_275 angularjs:-1.2.20 nginx:-1.16.1 chrome:-87.0.4280.88版本
我的Angular 代码如下

helloApp
    .controller(
        "HttpController",
        [
            '$scope',
            '$http',
            '$window',
            '$location',
            function($scope, $http, $window, $location) {
                $scope.pagesize = 50;
                $scope.uploadresponse = {};
                $scope.failmessage = '';
                $scope.message = '';
                $scope.myVar = true;
                $scope.nonchars = '^|€{}[]~\\';
                $scope.dsm = false;
                $scope.uploadSMSAndRecipients = function() {
                    $('#smsrecordsverified').hide();
                    $('#bulkuploadfail').hide();
                    // $('#LoadingImageDiv').show();
                    $('#LoadingImageDivCancel').show();
                    $("#startupload").attr("disabled", true);

                    $('#downloadsamplefile').hide();
                    $("#inputfile").attr("disabled", true);
                    // $('#cancelProcessDiv').show();
                    var file = $scope.bulksmsfile;
                    console.log('file is ');
                    console.dir(file);
                    var uploadUrl = contextPath
                        + '/clientres/uploadSMSfile?dsm=' + $scope.dsm;
                    // fileUpload.uploadFileToUrl(file, uploadUrl);

                    //
                    var fd = new FormData();
                    fd.append('file', file);
                    var config = {
                                transformRequest: angular.identity,
                                headers: {
                                    'Content-Type': undefined
                                },
                                'timeout' : 300000
                            };

                    $http
                        .post(
                            uploadUrl,
                            fd,
                            config)
                        .success(
                            function(data) {
                                console.log("success");
                                if (data != '') {/*
                                                                         * $scope.uploadresponse =
                                                                         * data; //
                                                                         * console.log($scope.uploadresponse.batch.length);
                                                                         * $('#LoadingImageDiv')
                                                                         * .hide();
                                                                         * $('#uploadbulksmsdiv')
                                                                         * .hide();
                                                                         * $('#smsrecords').hide();
                                                                         * if
                                                                         * ($scope.uploadresponse.nonSMSChars) { $(
                                                                         * "#msgdetailspopup1")
                                                                         * .modal(); }
                                                                         * else { $(
                                                                         * '#smsrecordsverified')
                                                                         * .show(); }
                                                                         */

                                    if (data.failMessage == ''
                                        || data.failMessage == null) {

                                        $scope.uploadresponse = data;
                                        // console.log($scope.uploadresponse.batch.length);
                                        $(
                                            '#LoadingImageDivCancel')
                                            .hide();

                                        /*
                                         * $(
                                         * '#cancelProcessDiv')
                                         * .hide();
                                         */
                                        $(
                                            '#downloadsamplefile')
                                            .hide();
                                        $("#startupload")
                                            .attr(
                                                "disabled",
                                                false);
                                        $("#inputfile")
                                            .attr(
                                                "disabled",
                                                false);
                                        $(
                                            '#uploadbulksmsdiv')
                                            .hide();
                                        $('#smsrecords')
                                            .hide();
                                        if ($scope.uploadresponse.nonSMSChars) {
                                            $(
                                                "#msgdetailspopup1")
                                                .modal();
                                        } else {
                                            $(
                                                '#smsrecordsverified')
                                                .show();
                                        }
                                    } else {
                                        $(
                                            '#LoadingImageDivCancel')
                                            .hide();
                                        /*
                                         * $(
                                         * '#cancelProcessDiv')
                                         * .hide();
                                         */
                                        $(
                                            '#downloadsamplefile')
                                            .show();
                                        $("#startupload")
                                            .attr(
                                                "disabled",
                                                false);
                                        /*
                                         * $(
                                         * "#downloadsamplefile")
                                         * .attr(
                                         * "disabled",
                                         * false);
                                         */
                                        $("#inputfile")
                                            .attr(
                                                "disabled",
                                                false);
                                        $scope.failmessage = data.failMessage;
                                        $('#bulkuploadfail')
                                            .show();
                                    }

                                } else {
                                    $(
                                        '#LoadingImageDivCancel')
                                        .hide();/*
                                                                         * $('#cancelProcessDiv')
                                                                         * .hide();
                                                                         */
                                    $('#downloadsamplefile')
                                        .show();
                                    $("#startupload").attr(
                                        "disabled",
                                        false);
                                    /*
                                     * $(
                                     * "#downloadsamplefile")
                                     * .attr( "disabled",
                                     * false);
                                     */
                                    $("#inputfile").attr(
                                        "disabled",
                                        false);
                                    $scope.failmessage = 'Failed to upload the file.Please try again.';
                                    $('#bulkuploadfail')
                                        .show();

                                }

                                /*
                                 * $scope.paidLearners =
                                 * data;
                                 * console.log($scope.paidLearners.length);
                                 * $('#LoadingImageDiv').hide();
                                 * $('#addPaidLearner').hide();
                                 * $('#successpanel').hide();
                                 * $('#bulkuploadsuccess').show();
                                 */
                            })
                        .error(
                            function(data) {
                                console.log("error");
                                // $scope.failmessage =
                                // 'Something went
                                // wrong.Please try again.';
                                if ($scope.filesize != '')
                                    $scope.failmessage = $scope.filesize;
                                else

                                    $scope.failmessage = 'Something went wrong.Please try again.';
                                $('#downloadsamplefile')
                                    .show();
                                $("#startupload").attr(
                                    "disabled", false);
                                /*
                                 * $( "#downloadsamplefile")
                                 * .attr( "disabled",
                                 * false);
                                 */
                                $("#inputfile").attr(
                                    "disabled", false);
                                $('#bulkuploadfail').show();
                                $('#LoadingImageDivCancel')
                                    .hide();
                                $('#cancelProcessDiv')
                                    .hide();
                                // $('#failpanel').show();
                            });

$scope.showUpload = function() {
                    /*
                     * $('#uploadbulksmsdiv').show();
                     * $scope.bulksmsfile = '';
                     */
                    $window.location.reload();
                }
                $scope.processSMS = function() {
                    $('#LoadingImageDiv').show();

                    var response = $http.post(contextPath
                        + '/clientres/confirmBulkSend',
                        $scope.uploadresponse);
                    response
                        .success(function(data, status,
                            headers, config) {
                            if (data != '') {
                                $scope.response = data;
                                $('#success').show();
                                $('#smsrecords').hide();
                                $('#LoadingImageDiv').hide();
                                $('#smsrecordsverified').hide();
                            } else {
                                $scope.failmessage = 'Failed to send the sms.Please try again.';
                                $('#bulkuploadfail').show();
                                $('#smsrecords').hide();
                                $('#smsrecordsverified').hide();
                            }
                        });
                    response
                        .error(function(data, status, headers,
                            config) {
                            $scope.failmessage = 'Something went wrong.Please try again.';
                            $('#smsrecords').hide();
                            $('#bulkuploadfail').show();
                            $('#LoadingImageDiv').hide();
                            $('#smsrecordsverified').hide();
                        });
                }}}])

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题