From 701633b50b586091418d934f1c9a754cef2b487e Mon Sep 17 00:00:00 2001 From: Vincent Dolez Date: Sun, 20 Nov 2016 19:58:50 +0100 Subject: [PATCH 1/4] get video height and width --- src/validate.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/validate.js b/src/validate.js index 100a3f71..86e3e4e5 100644 --- a/src/validate.js +++ b/src/validate.js @@ -282,19 +282,19 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct var deffer = $q.defer(); var promises = []; - promises.push(validateAsync('maxHeight', 'height.max', /image/, + promises.push(validateAsync('maxHeight', 'height.max', /image|video/, this.imageDimensions, function (d, val) { return d.height <= val; })); - promises.push(validateAsync('minHeight', 'height.min', /image/, + promises.push(validateAsync('minHeight', 'height.min', /image|video/, this.imageDimensions, function (d, val) { return d.height >= val; })); - promises.push(validateAsync('maxWidth', 'width.max', /image/, + promises.push(validateAsync('maxWidth', 'width.max', /image|video/, this.imageDimensions, function (d, val) { return d.width <= val; })); - promises.push(validateAsync('minWidth', 'width.min', /image/, + promises.push(validateAsync('minWidth', 'width.min', /image|video/, this.imageDimensions, function (d, val) { return d.width >= val; })); @@ -304,7 +304,7 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct }, function (r) { return r; })); - promises.push(validateAsync('ratio', null, /image/, + promises.push(validateAsync('ratio', null, /image|video/, this.imageDimensions, function (d, val) { var split = val.toString().split(','), valid = false; for (var i = 0; i < split.length; i++) { @@ -314,21 +314,21 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct } return valid; })); - promises.push(validateAsync('maxRatio', 'ratio.max', /image/, + promises.push(validateAsync('maxRatio', 'ratio.max', /image|video/, this.imageDimensions, function (d, val) { return (d.width / d.height) - upload.ratioToFloat(val) < 0.0001; })); - promises.push(validateAsync('minRatio', 'ratio.min', /image/, + promises.push(validateAsync('minRatio', 'ratio.min', /image|video/, this.imageDimensions, function (d, val) { return (d.width / d.height) - upload.ratioToFloat(val) > -0.0001; })); promises.push(validateAsync('maxDuration', 'duration.max', /audio|video/, this.mediaDuration, function (d, val) { - return d <= upload.translateScalars(val); + return d.duration <= upload.translateScalars(val); })); promises.push(validateAsync('minDuration', 'duration.min', /audio|video/, this.mediaDuration, function (d, val) { - return d >= upload.translateScalars(val); + return d.duration >= upload.translateScalars(val); })); promises.push(validateAsync('duration', null, /audio|video/, function (file, val) { @@ -378,8 +378,12 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct var deferred = $q.defer(); $timeout(function () { if (file.type.indexOf('image') !== 0) { - deferred.reject('not image'); - return; + if(file.type.indexOf('video') === 0){ + return upload.mediaDuration(file); + } else { + deferred.reject('not image'); + return; + } } upload.dataUrl(file).then(function (dataUrl) { var img = angular.element('').attr('src', dataUrl) @@ -437,7 +441,7 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct if (file.$ngfDuration) { var d = $q.defer(); $timeout(function () { - d.resolve(file.$ngfDuration); + d.resolve({width: file.$ngfWidth, height: file.$ngfHeight, duration: file.$ngfDuration}); }); return d.promise; } @@ -456,8 +460,14 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct function success() { var duration = el[0].duration; file.$ngfDuration = duration; + if(file.type.indexOf('video')===0){ + var width = el[0].videoWidth, + var height = el[0].videoHeight; + file.$ngfWidth = width; + file.$ngfHeight = height; + } el.remove(); - deferred.resolve(duration); + deferred.resolve({width: width, height: height, duration: duration}); } function error() { From 22e8c1be295df3f08d40c8dbcfe382d6447d5f69 Mon Sep 17 00:00:00 2001 From: Vincent Dolez Date: Sun, 20 Nov 2016 20:08:23 +0100 Subject: [PATCH 2/4] fix --- src/validate.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/validate.js b/src/validate.js index 86e3e4e5..dbbcb929 100644 --- a/src/validate.js +++ b/src/validate.js @@ -298,7 +298,7 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct this.imageDimensions, function (d, val) { return d.width >= val; })); - promises.push(validateAsync('dimensions', null, /image/, + promises.push(validateAsync('dimensions', null, /image|video/, function (file, val) { return upload.emptyPromise(val); }, function (r) { @@ -387,8 +387,8 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct } upload.dataUrl(file).then(function (dataUrl) { var img = angular.element('').attr('src', dataUrl) - .css('visibility', 'hidden').css('position', 'fixed') - .css('max-width', 'none !important').css('max-height', 'none !important'); + .css('visibility', 'hidden').css('position', 'fixed') + .css('max-width', 'none !important').css('max-height', 'none !important'); function success() { var width = img[0].naturalWidth || img[0].clientWidth; @@ -455,13 +455,13 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct } upload.dataUrl(file).then(function (dataUrl) { var el = angular.element(file.type.indexOf('audio') === 0 ? '