上传大于30 MB的文件时,为什么Chrome和Firefox会崩溃?

时间:2014-12-05 11:37:43

标签: javascript angularjs google-chrome firefox file-upload

我正在尝试在我的angularjs应用程序中上传服务器上的文件。该文件以base64字符串格式上传。当文件大小小于30 MB但浏览器(chrome和firefox)在文件大小超过30 MB时崩溃的情况下工作正常。浏览器在发出请求之前崩溃。

以下是我的控制器上传文件的代码:

$scope.addMyFile = function(t,pid,id,week,day) {
    $("#upload"+t+pid+id).each(function() {
           var $input = $(this);
           var inputFiles = this.files;
               if(inputFiles == undefined || inputFiles.length == 0) return;
           var inputFile = inputFiles[0];
           var inputFileSize = inputFile.size;

           var reader = new FileReader();
           reader.onload = function(event) {
               var dataString = event.target.result;

               var firstPart =  dataString.split(',')[0];
               var secondPart = dataString.split(',')[1];

               dataString = secondPart;

               var fileName = inputFile.name;

               var fileExtension = firstPart.split('/')[1].split(';')[0];

               reader.readAsDataURL(inputFile);
       });
};

UploadMyFile功能:

$scope.uploadFile = function(type,week,day,fileName,fileExtension,dataString) {
$scope.loading = true;
$scope.uploadBar = true;

var fileUploadUrl = serverURL;

var request = $http({
        method: "POST",
        url: fileUploadUrl, 
        headers: { 'Accept' :'application/json','Content-Type' :'application/json', authToken:userauthToken, 'Accept-Language': 'en'},
        data: { name : fileName, documentString:dataString, extension: fileExtension}
     });

     request.success(
       function(data) {
           $scope.uploadStatus = data.status;
           $scope.getWeekList(type);
           $scope.uploadBar = false;
           alert('The file has been successfully uploaded.');
     });
     $scope.loading = false;
     request.error(
        function(data, status) {
            console.log(status);
            $scope.uploadStatus = data.status || "Request failed";
            alert('The file could not be uploaded. Please try again.');
     });
};

0 个答案:

没有答案