dqn8235 2017-03-22 01:53
浏览 216
已采纳

上传一个巨大的文件〜2GB大小会导致浏览器错误

I want to upload huge file. So I chunk a huge file into 10Mb blobs.

Uploading with files around 200Mb works well.

But uploading 2GB files, Chrome`s console error:

net::ERR_FILE_NOT_FOUND

My environment:

Chrome 53

My code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="//cdn.bootcss.com/jquery/2.2.4/jquery.js"></script>
    <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<div ng-app="testapp" ng-controller="testctl">
    <input type="file" id="file">
    <input type="button" ng-click="one()" value="test_split_upload">
</div>

<script>

    (function () {
        'use strict';
        angular
                .module('testapp', [
                ])
                .controller('testctl',['$scope','$http','$q',function ($scope,$http,$q) {
                    $scope.one = function () {
                        $scope.file = $('#file').get(0).files[0];
                        $scope.splitfilea(1);
                    };

                    $scope.splitfilea = function (currentpage) {
                        let persize=1024*1024*10; //10Mb
                        let allpage = Math.ceil($scope.file.size/persize);
                        let start = (currentpage-1)*persize;
                        let end = start+persize;
                        if(currentpage===allpage){
                            end=$scope.file.size;
                        }
                        $scope.filesplitdata = $scope.file.slice(start, end);
                        $scope.r = new FileReader();
                        $scope.r.readAsDataURL($scope.filesplitdata);
                        $scope.r.onloadend=function (e) {
                            console.log(currentpage);
                            var bolb = e.target.result;
                            $scope.encode_blob = new Blob([bolb]);
                            $q.when($scope.httppost($scope.encode_blob)).then(function () {
                                delete $scope.formData;
                                if(currentpage<=allpage){
                                    currentpage = currentpage+1;
                                    $scope.splitfilea(currentpage);
                                }else{
                                    console.log('end');
                                }
                            });
                        };
                    };

                    $scope.httppost = function (blob) {
                        var deferral_local = $q.defer();
                        $http({
                        method: 'POST',
                        url: '/test/up4/1.php',
                        headers: {
                            'Content-Type': undefined
                        },
                        data: {
                            abc: blob,
                            filename:"xxxxxxx.txt",
                            type:"xxxxxx"
                        },
                        transformRequest: function (data, headersGetter) {
                            if(!$scope.formData){
                                $scope.formData = new FormData();
                            }
                            angular.forEach(data, function (value, key) {
                                if(key === "abc"){
                                    $scope.formData.append(key, value,"xxx.txt");
                                }else{
                                    $scope.formData.append(key, value);
                                }
                            });
                            var headers = headersGetter();
                            delete headers['Content-Type'];

                            return $scope.formData;
                        }
                    }).success(function (response) {
                            deferral_local.resolve( { status: 'good' } );
                        });
                        return deferral_local.promise;
                    };

                }]);
    }());

</script>

</body>
</html>

And the 4.php is empty.

<?php

?>
  • 写回答

2条回答 默认 最新

  • drdyszuy488152 2017-03-23 06:15
    关注

    This is Chrome`s Bug About This: https://bugs.chromium.org/p/chromium/issues/detail?id=375297

    I upgrade the Chrome to 57 , And all files works well... ^_^

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?