修改Angularjs中的输入类型结构

时间:2019-03-07 20:49:51

标签: javascript angularjs ng-file-upload

我有一个输入类型文件,可以选择多个文件,并且我正在使用ng-file-upload将这些文件上传到服务器。当用户选择视频时,我尝试添加视频时长,但是当我发送到服务器时,该变量不会出现。

1)是否可以将持续时间添加到文件结构中? 2)有什么解决方法可以发送带有文件的持续时间吗?

这是我的代码

<div ngf-select="upload_to_server($files)" ngf-drop="upload_to_server($files)" ng-model="files" 
  ngf-model-invalid="invalidFiles" ngf-multiple="true" ngf-pattern="'image/*,audio/*,video/*'" 
  ngf-accept="'image/*,audio/*,video/*'" ng-disabled="false" ngf-validate="{size: {max: '900MB'}}" 
  ngf-fix-orientation="true" class="drop-box grey-text text-darken-1 quicksand">
  Select o drop an image/audio/video
</div>


$scope.upload_to_server = function (files) {
array_durations = []
if (files && files.length) {
  for (var i=0;i<files.length;i++){
    array_durations.push(GetDurations(files, i))
  }
  Promise.all(array_durations).then(response => {
    for(var i=0;i<response.length;i++){
      for(var j=0;j<response[i].length;j++){
        if(response[i][j].name == files[i].name){
          files[i].duracion_video = response[i][j].duracion_video; //here I add to the structure
        }
      }
    }
    Upload.upload({
      url: 'url_Base/',
      method: 'POST',
      headers: {"Authorization": "Basic " + $scope.authentication, "Content-Type": "application/json"},
      data: { "array": files }
    }).then(function (response) {
      $timeout(function () {
        $scope.result = response.data;
      });
    }, function (response) {
      if (response.status > 0) {
        $scope.errorMsg = response.status + ': ' + response.data;
      }
    }, function (evt) {
      $scope.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
    });
  }).catch(err => {
    console.log("Error 305 line "+err);
  }) 
}
};

function GetDurations(files, i){
return new Promise(function(resolve, reject){
  res = []
  Upload.mediaDuration(files[i]).then(function(durationInSeconds){
    res.push({"name": files[i].name, "duracion_video":durationInSeconds})
    resolve(res)
  });
})
}

总结为了获得时长视频,我在Promise中使用GetDurations(),然后将其添加到结构中,但是我的服务器无法识别,这是什么问题?预先感谢

0 个答案:

没有答案