У меня есть файл типа ввода, который позволяет выбрать несколько файлов, и я использую 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)
});
})
}
В заключение. Чтобы получить длительность видео, я использую GetDurations () в обещании и после этого добавляю в структуру, но мой сервер не распознает, Что не так? Заранее спасибо