-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Danial Farid
authored and
Danial Farid
committed
Jan 22, 2016
1 parent
8e673e3
commit d6f1cba
Showing
20 changed files
with
156 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* progress, resize, thumbnail, preview, validation and CORS | ||
* FileAPI Flash shim for old browsers not supporting FormData | ||
* @author Danial <[email protected]> | ||
* @version 11.2.1 | ||
* @version 11.2.2 | ||
*/ | ||
|
||
(function () { | ||
|
@@ -424,7 +424,7 @@ if (!window.FileReader) { | |
* AngularJS file upload directives and services. Supoorts: file upload/drop/paste, resume, cancel/abort, | ||
* progress, resize, thumbnail, preview, validation and CORS | ||
* @author Danial <[email protected]> | ||
* @version 11.2.1 | ||
* @version 11.2.2 | ||
*/ | ||
|
||
if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | ||
|
@@ -445,7 +445,7 @@ if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | |
|
||
var ngFileUpload = angular.module('ngFileUpload', []); | ||
|
||
ngFileUpload.version = '11.2.1'; | ||
ngFileUpload.version = '11.2.2'; | ||
|
||
ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) { | ||
var upload = this; | ||
|
@@ -645,11 +645,11 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, | |
return clone; | ||
} | ||
|
||
this.upload = function (config, internal) { | ||
function isFile(file) { | ||
return file != null && (file instanceof window.Blob || (file.flashId && file.name && file.size)); | ||
} | ||
this.isFile = function (file) { | ||
return file != null && (file instanceof window.Blob || (file.flashId && file.name && file.size)); | ||
}; | ||
|
||
this.upload = function (config, internal) { | ||
function toResumeFile(file, formData) { | ||
if (file._ngfBlob) return file; | ||
config._file = config._file || file; | ||
|
@@ -679,7 +679,7 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, | |
} | ||
if (angular.isString(val)) { | ||
formData.append(key, val); | ||
} else if (isFile(val)) { | ||
} else if (upload.isFile(val)) { | ||
var file = toResumeFile(val, formData); | ||
var split = key.split(','); | ||
if (split[1]) { | ||
|
@@ -787,6 +787,21 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, | |
return str; | ||
}; | ||
|
||
this.urlToBlob = function(url) { | ||
var defer = $q.defer(); | ||
$http({url: url, method: 'get', responseType: 'arraybuffer'}).then(function (resp) { | ||
var arrayBufferView = new Uint8Array(resp.data); | ||
var type = resp.headers('content-type') || 'image/WebP'; | ||
var blob = new window.Blob([arrayBufferView], {type: type}); | ||
defer.resolve(blob); | ||
//var split = type.split('[/;]'); | ||
//blob.name = url.substring(0, 150).replace(/\W+/g, '') + '.' + (split.length > 1 ? split[1] : 'jpg'); | ||
}, function (e) { | ||
defer.reject(e); | ||
}); | ||
return defer.promise; | ||
}; | ||
|
||
this.setDefaults = function (defaults) { | ||
this.defaults = defaults || {}; | ||
}; | ||
|
@@ -1580,6 +1595,9 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct | |
if (ngModel) { | ||
ngModel.$formatters.push(function (files) { | ||
if (ngModel.$dirty) { | ||
if (!angular.isArray(files)) { | ||
files = [files]; | ||
} | ||
upload.validate(files, ngModel, attr, scope).then(function () { | ||
upload.applyModelValidation(ngModel, files); | ||
}); | ||
|
@@ -2258,13 +2276,8 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa | |
var promises = [], files = []; | ||
if (urls.length) { | ||
angular.forEach(urls, function (url) { | ||
promises.push($http({url: url, method: 'get', responseType: 'arraybuffer'}).then(function (resp) { | ||
var arrayBufferView = new Uint8Array(resp.data); | ||
var type = resp.headers('content-type') || 'image/WebP'; | ||
var blob = new window.Blob([arrayBufferView], {type: type}); | ||
promises.push(upload.urlToBlob(url).then(function (blob) { | ||
files.push(blob); | ||
//var split = type.split('[/;]'); | ||
//blob.name = url.substring(0, 150).replace(/\W+/g, '') + '.' + (split.length > 1 ? split[1] : 'jpg'); | ||
})); | ||
}); | ||
var defer = $q.defer(); | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* progress, resize, thumbnail, preview, validation and CORS | ||
* FileAPI Flash shim for old browsers not supporting FormData | ||
* @author Danial <[email protected]> | ||
* @version 11.2.1 | ||
* @version 11.2.2 | ||
*/ | ||
|
||
(function () { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* AngularJS file upload directives and services. Supoorts: file upload/drop/paste, resume, cancel/abort, | ||
* progress, resize, thumbnail, preview, validation and CORS | ||
* @author Danial <[email protected]> | ||
* @version 11.2.1 | ||
* @version 11.2.2 | ||
*/ | ||
|
||
if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | ||
|
@@ -23,7 +23,7 @@ if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | |
|
||
var ngFileUpload = angular.module('ngFileUpload', []); | ||
|
||
ngFileUpload.version = '11.2.1'; | ||
ngFileUpload.version = '11.2.2'; | ||
|
||
ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) { | ||
var upload = this; | ||
|
@@ -223,11 +223,11 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, | |
return clone; | ||
} | ||
|
||
this.upload = function (config, internal) { | ||
function isFile(file) { | ||
return file != null && (file instanceof window.Blob || (file.flashId && file.name && file.size)); | ||
} | ||
this.isFile = function (file) { | ||
return file != null && (file instanceof window.Blob || (file.flashId && file.name && file.size)); | ||
}; | ||
|
||
this.upload = function (config, internal) { | ||
function toResumeFile(file, formData) { | ||
if (file._ngfBlob) return file; | ||
config._file = config._file || file; | ||
|
@@ -257,7 +257,7 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, | |
} | ||
if (angular.isString(val)) { | ||
formData.append(key, val); | ||
} else if (isFile(val)) { | ||
} else if (upload.isFile(val)) { | ||
var file = toResumeFile(val, formData); | ||
var split = key.split(','); | ||
if (split[1]) { | ||
|
@@ -365,6 +365,21 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, | |
return str; | ||
}; | ||
|
||
this.urlToBlob = function(url) { | ||
var defer = $q.defer(); | ||
$http({url: url, method: 'get', responseType: 'arraybuffer'}).then(function (resp) { | ||
var arrayBufferView = new Uint8Array(resp.data); | ||
var type = resp.headers('content-type') || 'image/WebP'; | ||
var blob = new window.Blob([arrayBufferView], {type: type}); | ||
defer.resolve(blob); | ||
//var split = type.split('[/;]'); | ||
//blob.name = url.substring(0, 150).replace(/\W+/g, '') + '.' + (split.length > 1 ? split[1] : 'jpg'); | ||
}, function (e) { | ||
defer.reject(e); | ||
}); | ||
return defer.promise; | ||
}; | ||
|
||
this.setDefaults = function (defaults) { | ||
this.defaults = defaults || {}; | ||
}; | ||
|
@@ -1158,6 +1173,9 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct | |
if (ngModel) { | ||
ngModel.$formatters.push(function (files) { | ||
if (ngModel.$dirty) { | ||
if (!angular.isArray(files)) { | ||
files = [files]; | ||
} | ||
upload.validate(files, ngModel, attr, scope).then(function () { | ||
upload.applyModelValidation(ngModel, files); | ||
}); | ||
|
@@ -1836,13 +1854,8 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa | |
var promises = [], files = []; | ||
if (urls.length) { | ||
angular.forEach(urls, function (url) { | ||
promises.push($http({url: url, method: 'get', responseType: 'arraybuffer'}).then(function (resp) { | ||
var arrayBufferView = new Uint8Array(resp.data); | ||
var type = resp.headers('content-type') || 'image/WebP'; | ||
var blob = new window.Blob([arrayBufferView], {type: type}); | ||
promises.push(upload.urlToBlob(url).then(function (blob) { | ||
files.push(blob); | ||
//var split = type.split('[/;]'); | ||
//blob.name = url.substring(0, 150).replace(/\W+/g, '') + '.' + (split.length > 1 ? split[1] : 'jpg'); | ||
})); | ||
}); | ||
var defer = $q.defer(); | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.