使用angularjs上传大mp4视频文件

时间:2017-02-11 20:26:42

标签: angularjs rest video file-upload upload

我想使用rest api在我的角度应用程序中上传大mp4视频文件(500MB - 1GB)(如果可能的话,先压缩它们)。我尝试使用ng-file-upload,但它不适用于大于20Mb的视频。

请问我该如何完成这项任务?

PS:我的服务器端是用PHP编写的

2 个答案:

答案 0 :(得分:0)

从上面的描述中可以看出,可以上传的最大文件大小可能存在服务器限制 - 这很常见,设置或更改最大大小的方式取决于服务器。这里的示例是AWS S3存储的一些配置,它显示了最小和最大文件大小:

   var s3Policy = {
        'expiration': expiration,
        'conditions': [{
                'bucket': aws.bucket
            },
            ['starts-with', '$key', path], 
            {
                'acl': readType
            },
            {
              'success_action_status': '201'
            },
            ['starts-with', '$Content-Type', request.type],
            ['content-length-range', 2048, 124857600], //min and max
        ]
    };

如果您只需要一些示例Angular代码用于视频上传,那么下面的代码就是如何将视频从网页/应用程序上传到服务器的示例 - 它是AngularJS 1:

// Controls video upload from web uses module and apraoch at: https://github.com/danialfarid/angular-file-upload
app.controller('WebUploadCtrl',[ '$scope', '$upload','colabConfig', function($scope, $upload, colabConfig) {
    console.log("WebUploadCtrl controller");
    $scope.progressPerCent = 0;
    $scope.onFileSelect = function($files) {
        console.log("file selected for upload...");
        //$files: an array of files selected, each file has name, size, and type.
        for (var i = 0; i < $files.length; i++) {
          var file = $files[i];
          $scope.upload = $upload.upload({
            url: yourConfig.yourBaseURL + "/web_video_upload",
            method: 'POST',
            //headers: {'header-key': 'header-value'},
            //withCredentials: true,
            data: {myObj: $scope.myModelObj},
            file: file,
          }).progress(function(evt) {
              console.log("progress: " + (evt.position/evt.totalSize)*100);
              //$scope.$apply(function() {
                  $scope.progressPerCent = (evt.position/evt.totalSize)*100;
              //});
          }).success(function(data, status, headers, config) {
            // file is uploaded successfully
            console.log(data);
          }).error(function() {
            console.log("Error on web video upload");
          });
        }
    }
}]);

答案 1 :(得分:0)

您可以尝试在Web配置文件中增加属性

    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="30000000" />
      </requestFiltering>
    </security>