Skip to content

Commit

Permalink
11.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Danial Farid authored and Danial Farid committed Jan 22, 2016
1 parent afa48b6 commit c6d0db8
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 37 deletions.
2 changes: 1 addition & 1 deletion FileAPI.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 27 additions & 14 deletions ng-file-upload-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* progress, resize, thumbnail, preview, validation and CORS
* FileAPI Flash shim for old browsers not supporting FormData
* @author Danial <danial.farid@gmail.com>
* @version 11.2.1
* @version 11.2.2
*/

(function () {
Expand Down Expand Up @@ -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 <danial.farid@gmail.com>
* @version 11.2.1
* @version 11.2.2
*/

if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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 || {};
};
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions ng-file-upload-all.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ng-file-upload-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* progress, resize, thumbnail, preview, validation and CORS
* FileAPI Flash shim for old browsers not supporting FormData
* @author Danial <danial.farid@gmail.com>
* @version 11.2.1
* @version 11.2.2
*/

(function () {
Expand Down
2 changes: 1 addition & 1 deletion ng-file-upload-shim.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 26 additions & 13 deletions ng-file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <danial.farid@gmail.com>
* @version 11.2.1
* @version 11.2.2
*/

if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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 || {};
};
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions ng-file-upload.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: "danialf:ng-file-upload",
"version": "11.2.1",
"version": "11.2.2",
summary: "Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support",
git: "https://github.com/danialfarid/ng-file-upload.git"
});
Expand Down

0 comments on commit c6d0db8

Please sign in to comment.