diff --git a/demo/src/com/df/angularfileupload/FileUpload.java b/demo/src/com/df/angularfileupload/FileUpload.java index 4c5e3bcf..8dde563c 100644 --- a/demo/src/com/df/angularfileupload/FileUpload.java +++ b/demo/src/com/df/angularfileupload/FileUpload.java @@ -21,9 +21,13 @@ public class FileUpload extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { try { + if (req.getParameter("errorCode") != null) { +// res.getWriter().write(req.getParameter("errorMessage")); +// res.getWriter().flush(); + res.sendError(Integer.parseInt(req.getParameter("errorCode")), req.getParameter("errorMessage")); + return; + } StringBuilder sb = new StringBuilder("{\"result\": ["); - int errorCode = 0; - String errorMsg = null; if (req.getHeader("Content-Type") != null && req.getHeader("Content-Type").startsWith("multipart/form-data")) { @@ -33,18 +37,6 @@ protected void service(HttpServletRequest req, HttpServletResponse res) throws S while (iterator.hasNext()) { FileItemStream item = iterator.next(); - if (item.getFieldName() != null && item.getFieldName().equals("errorCode")) { - String val = read(item.openStream()); - try { - errorCode = Integer.parseInt(val); - } catch(NumberFormatException e) {} - continue; - } - if (item.getFieldName() != null && item.getFieldName().equals("errorMessage")) { - String val = read(item.openStream()); - errorMsg = val; - continue; - } sb.append("{"); sb.append("\"fieldName\":\"").append(item.getFieldName()).append("\","); if (item.getName() != null) { @@ -77,12 +69,7 @@ protected void service(HttpServletRequest req, HttpServletResponse res) throws S } sb.append("}}"); - if (errorCode != 0) { - res.setStatus(errorCode); - res.getWriter().write(errorMsg); - } else { - res.getWriter().write(sb.toString()); - } + res.getWriter().write(sb.toString()); } catch (Exception ex) { throw new ServletException(ex); } diff --git a/demo/war/js/angular-file-upload-all.js b/demo/war/js/angular-file-upload-all.js index 9fada053..98503600 100644 --- a/demo/war/js/angular-file-upload-all.js +++ b/demo/war/js/angular-file-upload-all.js @@ -1,7 +1,7 @@ /**! * AngularJS file upload/drop directive with progress and abort * @author Danial - * @version 2.0.2 + * @version 2.0.3 */ (function() { @@ -26,7 +26,7 @@ if (window.XMLHttpRequest && !window.XMLHttpRequest.__isFileAPIShim) { } var angularFileUpload = angular.module('angularFileUpload', []); -angularFileUpload.version = '2.0.2'; +angularFileUpload.version = '2.0.3'; angularFileUpload.service('$upload', ['$http', '$q', '$timeout', function($http, $q, $timeout) { function sendHttp(config) { config.method = config.method || 'POST'; @@ -193,8 +193,17 @@ function handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout) { } if (scope.resetOnClick() != false) { elem.bind('click', function(evt) { - this.value = null; - updateModel([], attr, ngModel, scope, evt); + if (elem[0].value) { + updateModel([], attr, ngModel, scope, evt); + } + elem[0].value = null; + }); + } + if (ngModel) { + scope.$parent.$watch(attr['ngModel'], function(val) { + if (val == null) { + elem[0].value = null; + } }); } if (attr['ngFileSelect'] != '') { @@ -465,7 +474,7 @@ function globStringToRegex(str) { * AngularJS file upload/drop directive with progress and abort * FileAPI Flash shim for old browsers not supporting FormData * @author Danial - * @version 2.0.2 + * @version 2.0.3 */ (function() { diff --git a/demo/war/js/angular-file-upload.js b/demo/war/js/angular-file-upload.js index 298ca870..6a1e3d97 100644 --- a/demo/war/js/angular-file-upload.js +++ b/demo/war/js/angular-file-upload.js @@ -193,8 +193,17 @@ function handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout) { } if (scope.resetOnClick() != false) { elem.bind('click', function(evt) { - this.value = null; - updateModel([], attr, ngModel, scope, evt); + if (elem[0].value) { + updateModel([], attr, ngModel, scope, evt); + } + elem[0].value = null; + }); + } + if (ngModel) { + scope.$parent.$watch(attr['ngModel'], function(val) { + if (val == null) { + elem[0].value = null; + } }); } if (attr['ngFileSelect'] != '') { diff --git a/demo/war/js/upload-http.js b/demo/war/js/upload-http.js index fe9185d5..a8b43a9d 100644 --- a/demo/war/js/upload-http.js +++ b/demo/war/js/upload-http.js @@ -2,7 +2,7 @@ var fileReader = new FileReader(); fileReader.onload = function(e) { $timeout(function() { file.upload = $upload.http({ - url: 'https://angular-file-upload-cors-srv.appspot.com/upload', + url: 'https://angular-file-upload-cors-srv.appspot.com/upload' + $scope.getReqParams(), method: 'POST', headers : { 'Content-Type': file.type diff --git a/demo/war/js/upload-upload.js b/demo/war/js/upload-upload.js index 9c27b5eb..253622d3 100644 --- a/demo/war/js/upload-upload.js +++ b/demo/war/js/upload-upload.js @@ -2,13 +2,8 @@ var data = $scope.formUpload ? { username: $scope.username } : {}; -if ($scope.generateErrorOnServer) { - data.errorCode = $scope.serverErrorCode; - data.errorMessage = $scope.serverErrorMsg; -} - file.upload = $upload.upload({ - url: 'https://angular-file-upload-cors-srv.appspot.com/upload', + url: 'https://angular-file-upload-cors-srv.appspot.com/upload' + $scope.getReqParams(), method: 'POST', headers: { 'my-header' : 'my-header-value' diff --git a/demo/war/js/upload.js b/demo/war/js/upload.js index 4f8bb87e..df9794b3 100644 --- a/demo/war/js/upload.js +++ b/demo/war/js/upload.js @@ -30,7 +30,7 @@ app.controller('MyCtrl', [ '$scope', '$http', '$timeout', '$compile', '$upload', } storeS3UploadConfigInLocalStore(); }; - + $scope.uploadPic = function(files) { $scope.formUpload = true; if (files != null) { @@ -144,4 +144,9 @@ app.controller('MyCtrl', [ '$scope', '$http', '$timeout', '$compile', '$upload', $scope.confirm = function() { return confirm('Are you sure? Your local changes will be lost.'); } + + $scope.getReqParams = function() { + return $scope.generateErrorOnServer ? "?errorCode=" + $scope.serverErrorCode + + "&errorMessage=" + $scope.serverErrorMsg : ""; + } } ]); diff --git a/dist/angular-file-upload-all.js b/dist/angular-file-upload-all.js index 9fada053..98503600 100644 --- a/dist/angular-file-upload-all.js +++ b/dist/angular-file-upload-all.js @@ -1,7 +1,7 @@ /**! * AngularJS file upload/drop directive with progress and abort * @author Danial - * @version 2.0.2 + * @version 2.0.3 */ (function() { @@ -26,7 +26,7 @@ if (window.XMLHttpRequest && !window.XMLHttpRequest.__isFileAPIShim) { } var angularFileUpload = angular.module('angularFileUpload', []); -angularFileUpload.version = '2.0.2'; +angularFileUpload.version = '2.0.3'; angularFileUpload.service('$upload', ['$http', '$q', '$timeout', function($http, $q, $timeout) { function sendHttp(config) { config.method = config.method || 'POST'; @@ -193,8 +193,17 @@ function handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout) { } if (scope.resetOnClick() != false) { elem.bind('click', function(evt) { - this.value = null; - updateModel([], attr, ngModel, scope, evt); + if (elem[0].value) { + updateModel([], attr, ngModel, scope, evt); + } + elem[0].value = null; + }); + } + if (ngModel) { + scope.$parent.$watch(attr['ngModel'], function(val) { + if (val == null) { + elem[0].value = null; + } }); } if (attr['ngFileSelect'] != '') { @@ -465,7 +474,7 @@ function globStringToRegex(str) { * AngularJS file upload/drop directive with progress and abort * FileAPI Flash shim for old browsers not supporting FormData * @author Danial - * @version 2.0.2 + * @version 2.0.3 */ (function() { diff --git a/dist/angular-file-upload-all.min.js b/dist/angular-file-upload-all.min.js index a127d0ce..a29486c0 100644 --- a/dist/angular-file-upload-all.min.js +++ b/dist/angular-file-upload-all.min.js @@ -1,2 +1,2 @@ -/*! 2.0.2 */ -!function(){function a(a,b){window.XMLHttpRequest.prototype[a]=b(window.XMLHttpRequest.prototype[a])}function b(a,b,c,d,e,f){function g(a,b,c,d,e){f(function(){for(var b=[],g=0;g');c.multiple&&h.attr("multiple",c.multiple),c.accept&&h.attr("accept",c.accept),h.css("width","1px").css("height","1px").css("opacity",0).css("position","absolute").css("filter","alpha(opacity=0)").css("padding",0).css("margin",0).css("overflow","hidden").attr("tabindex","-1").attr("ng-file-generated-elem",!0),b.append(h),b.__afu_fileClickDelegate__=function(){h[0].click()},b.bind("click",b.__afu_fileClickDelegate__),b.css("overflow","hidden"),b=h}0!=a.resetOnClick()&&b.bind("click",function(b){this.value=null,g([],c,d,a,b)}),""!=c.ngFileSelect&&(a.change=a.select),b.bind("change",function(b){var e;e=b.__files_||b.target.files,g(e,c,d,a,b)})}function c(a,b,c,g,h,i,j){function k(a,b,c){var d=!0;if(q){var e=c.dataTransfer.items;if(null!=e)for(var f=0;f0&&"file"!=j.protocol())for(var m=0;m0)break}else{var p=a.dataTransfer.files;if(null!=p)for(var m=0;m0));m++);}var r=0;!function t(a){i(function(){if(s)10*r++<2e4&&t(10);else{if(!d&&h.length>1){for(var a=0;"directory"==h[a].type;)a++;h=[h[a]]}b(h,k)}},a||0)}();var s=0}g&&g.$setViewValue("");var m=d();if(c.dropAvailable&&i(function(){a.dropAvailable=m}),!m)return 0!=a.hideOnDropNotAvailable()&&b.css("display","none"),void 0;var n=null,o=a.stopPropagation(),p=1,q=null==c.accept?null:new RegExp(f(c.accept));b[0].addEventListener("dragover",function(d){d.preventDefault(),o&&d.stopPropagation(),i.cancel(n),a.actualDragOverClass||(a.actualDragOverClass=k(a,c,d)),b.addClass(a.actualDragOverClass)},!1),b[0].addEventListener("dragenter",function(a){a.preventDefault(),o&&a.stopPropagation()},!1),b[0].addEventListener("dragleave",function(){n=i(function(){b.removeClass(a.actualDragOverClass),a.actualDragOverClass=null},p||1)},!1),""!=c.ngFileDrop&&(a.change=a.drop),b[0].addEventListener("drop",function(d){d.preventDefault(),o&&d.stopPropagation(),b.removeClass(a.actualDragOverClass),a.actualDragOverClass=null,l(d,function(b,e){g&&(a.fileModel=b,g&&g.$setViewValue(null!=b&&0==b.length?"":b)),c.ngFileRejectedModel&&(a.fileRejectedModel=e),i(function(){a.change({$files:b,$rejectedFiles:e,$event:d})})},0!=a.allowDir(),c.multiple)},!1)}function d(){var a=document.createElement("div");return"draggable"in a&&"ondrop"in a}function e(a){return/^[\000-\177]*$/.test(a)}function f(a){if(a.length>2&&"/"===a[0]&&"/"===a[a.length-1])return a.substring(1,a.length-1);var b=a.split(","),c="";if(b.length>1)for(var d=0;d|:\\-]","g"),"\\$&")+"$",c=c.replace(/\\\*/g,".*").replace(/\\\?/g,".");return c}window.XMLHttpRequest&&!window.XMLHttpRequest.__isFileAPIShim&&a("setRequestHeader",function(a){return function(b,c){if("__setXHR_"===b){var d=c(this);d instanceof Function&&d(this)}else a.apply(this,arguments)}});var g=angular.module("angularFileUpload",[]);g.version="2.0.2",g.service("$upload",["$http","$q","$timeout",function(a,b,c){function d(d){d.method=d.method||"POST",d.headers=d.headers||{},d.transformRequest=d.transformRequest||function(b,c){return window.ArrayBuffer&&b instanceof window.ArrayBuffer?b:a.defaults.transformRequest[0](b,c)};var e=b.defer(),f=e.promise;return d.headers.__setXHR_=function(){return function(a){a&&(d.__XHR=a,d.xhrFn&&d.xhrFn(a),a.upload.addEventListener("progress",function(a){a.config=d,e.notify?e.notify(a):f.progress_fn&&c(function(){f.progress_fn(a)})},!1),a.upload.addEventListener("load",function(a){a.lengthComputable&&(a.config=d,e.notify?e.notify(a):f.progress_fn&&c(function(){f.progress_fn(a)}))},!1))}},a(d).then(function(a){e.resolve(a)},function(a){e.reject(a)},function(a){e.notify(a)}),f.success=function(a){return f.then(function(b){a(b.data,b.status,b.headers,d)}),f},f.error=function(a){return f.then(null,function(b){a(b.data,b.status,b.headers,d)}),f},f.progress=function(a){return f.progress_fn=a,f.then(null,null,function(b){a(b)}),f},f.abort=function(){return d.__XHR&&c(function(){d.__XHR.abort()}),f},f.xhr=function(a){return d.xhrFn=function(b){return function(){b&&b.apply(f,arguments),a.apply(f,arguments)}}(d.xhrFn),f},f}this.upload=function(b){b.headers=b.headers||{},b.headers["Content-Type"]=void 0,b.transformRequest=b.transformRequest||a.defaults.transformRequest;var c=new FormData,e=b.transformRequest,f=b.data;return b.transformRequest=function(a,c){if(f)if(b.formDataAppender)for(var d in f){var g=f[d];b.formDataAppender(a,d,g)}else for(var d in f){var g=f[d];if("function"==typeof e)g=e(g,c);else for(var h=0;h-1&&a.apply(this,[b,"_fix_for_ie_crossdomain__",e])}}}),a("getResponseHeader",function(a){return function(b){return this.__fileApiXHR&&this.__fileApiXHR.getResponseHeader?this.__fileApiXHR.getResponseHeader(b):null==a?null:a.apply(this,[b])}}),a("getAllResponseHeaders",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.getAllResponseHeaders?this.__fileApiXHR.getAllResponseHeaders():null==a?null:a.apply(this)}}),a("abort",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.abort?this.__fileApiXHR.abort():null==a?null:a.apply(this)}}),a("setRequestHeader",function(a){return function(b,c){if("__setXHR_"===b){d(this);var e=c(this);e instanceof Function&&e(this)}else this.__requestHeaders=this.__requestHeaders||{},this.__requestHeaders[b]=c,a.apply(this,arguments)}}),a("send",function(a){return function(){var d=this;if(arguments[0]&&arguments[0].__isFileAPIShim){var e=arguments[0],f={url:d.__url,jsonp:!1,cache:!0,complete:function(a,c){d.__completed=!0,!a&&d.__listeners.load&&d.__listeners.load({type:"load",loaded:d.__loaded,total:d.__total,target:d,lengthComputable:!0}),!a&&d.__listeners.loadend&&d.__listeners.loadend({type:"loadend",loaded:d.__loaded,total:d.__total,target:d,lengthComputable:!0}),"abort"===a&&d.__listeners.abort&&d.__listeners.abort({type:"abort",loaded:d.__loaded,total:d.__total,target:d,lengthComputable:!0}),void 0!==c.status&&b(d,"status",function(){return 0==c.status&&a&&"abort"!==a?500:c.status}),void 0!==c.statusText&&b(d,"statusText",function(){return c.statusText}),b(d,"readyState",function(){return 4}),void 0!==c.response&&b(d,"response",function(){return c.response});var e=c.responseText||(a&&0==c.status&&"abort"!==a?a:void 0);b(d,"responseText",function(){return e}),b(d,"response",function(){return e}),a&&b(d,"err",function(){return a}),d.__fileApiXHR=c,d.onreadystatechange&&d.onreadystatechange(),d.onload&&d.onload()},fileprogress:function(a){if(a.target=d,d.__listeners.progress&&d.__listeners.progress(a),d.__total=a.total,d.__loaded=a.loaded,a.total===a.loaded){var b=this;setTimeout(function(){d.__completed||(d.getAllResponseHeaders=function(){},b.complete(null,{status:204,statusText:"No Content"}))},1e4)}},headers:d.__requestHeaders};f.data={},f.files={};for(var g=0;g',d=d.firstChild;var e=a.parentNode;e.insertBefore(d,a),e.removeChild(a),d.appendChild(a)}else b.addClass("js-fileapi-wrapper"),b.attr("ng-file-generated-elem")&&((""===b.parent().css("position")||"static"===b.parent().css("position"))&&b.parent().css("position","relative"),b.css("top",0).css("bottom",0).css("left",0).css("right",0).css("width","100%").css("height","100%").css("padding",0).css("margin",0),b.parent().unbind("click",b.parent().__afu_fileClickDelegate__))},f=function(a){return function(b){for(var c=FileAPI.getFiles(b),d=0;d-1){b=f.substring(0,e+1);break}null==FileAPI.staticPath&&(FileAPI.staticPath=b),g.setAttribute("src",a||b+"FileAPI.js"),document.getElementsByTagName("head")[0].appendChild(g),FileAPI.hasFlash=c()}}(),FileAPI.disableFileInput=function(a,b){b?a.removeClass("js-fileapi-wrapper"):a.addClass("js-fileapi-wrapper")}}window.FileReader||(window.FileReader=function(){var a=this,b=!1;this.listeners={},this.addEventListener=function(b,c){a.listeners[b]=a.listeners[b]||[],a.listeners[b].push(c)},this.removeEventListener=function(b,c){a.listeners[b]&&a.listeners[b].splice(a.listeners[b].indexOf(c),1)},this.dispatchEvent=function(b){var c=a.listeners[b.type];if(c)for(var d=0;d');c.multiple&&h.attr("multiple",c.multiple),c.accept&&h.attr("accept",c.accept),h.css("width","1px").css("height","1px").css("opacity",0).css("position","absolute").css("filter","alpha(opacity=0)").css("padding",0).css("margin",0).css("overflow","hidden").attr("tabindex","-1").attr("ng-file-generated-elem",!0),b.append(h),b.__afu_fileClickDelegate__=function(){h[0].click()},b.bind("click",b.__afu_fileClickDelegate__),b.css("overflow","hidden"),b=h}0!=a.resetOnClick()&&b.bind("click",function(e){b[0].value&&g([],c,d,a,e),b[0].value=null}),d&&a.$parent.$watch(c.ngModel,function(a){null==a&&(b[0].value=null)}),""!=c.ngFileSelect&&(a.change=a.select),b.bind("change",function(b){var e;e=b.__files_||b.target.files,g(e,c,d,a,b)})}function c(a,b,c,g,h,i,j){function k(a,b,c){var d=!0;if(q){var e=c.dataTransfer.items;if(null!=e)for(var f=0;f0&&"file"!=j.protocol())for(var m=0;m0)break}else{var p=a.dataTransfer.files;if(null!=p)for(var m=0;m0));m++);}var r=0;!function t(a){i(function(){if(s)10*r++<2e4&&t(10);else{if(!d&&h.length>1){for(var a=0;"directory"==h[a].type;)a++;h=[h[a]]}b(h,k)}},a||0)}();var s=0}g&&g.$setViewValue("");var m=d();if(c.dropAvailable&&i(function(){a.dropAvailable=m}),!m)return 0!=a.hideOnDropNotAvailable()&&b.css("display","none"),void 0;var n=null,o=a.stopPropagation(),p=1,q=null==c.accept?null:new RegExp(f(c.accept));b[0].addEventListener("dragover",function(d){d.preventDefault(),o&&d.stopPropagation(),i.cancel(n),a.actualDragOverClass||(a.actualDragOverClass=k(a,c,d)),b.addClass(a.actualDragOverClass)},!1),b[0].addEventListener("dragenter",function(a){a.preventDefault(),o&&a.stopPropagation()},!1),b[0].addEventListener("dragleave",function(){n=i(function(){b.removeClass(a.actualDragOverClass),a.actualDragOverClass=null},p||1)},!1),""!=c.ngFileDrop&&(a.change=a.drop),b[0].addEventListener("drop",function(d){d.preventDefault(),o&&d.stopPropagation(),b.removeClass(a.actualDragOverClass),a.actualDragOverClass=null,l(d,function(b,e){g&&(a.fileModel=b,g&&g.$setViewValue(null!=b&&0==b.length?"":b)),c.ngFileRejectedModel&&(a.fileRejectedModel=e),i(function(){a.change({$files:b,$rejectedFiles:e,$event:d})})},0!=a.allowDir(),c.multiple)},!1)}function d(){var a=document.createElement("div");return"draggable"in a&&"ondrop"in a}function e(a){return/^[\000-\177]*$/.test(a)}function f(a){if(a.length>2&&"/"===a[0]&&"/"===a[a.length-1])return a.substring(1,a.length-1);var b=a.split(","),c="";if(b.length>1)for(var d=0;d|:\\-]","g"),"\\$&")+"$",c=c.replace(/\\\*/g,".*").replace(/\\\?/g,".");return c}window.XMLHttpRequest&&!window.XMLHttpRequest.__isFileAPIShim&&a("setRequestHeader",function(a){return function(b,c){if("__setXHR_"===b){var d=c(this);d instanceof Function&&d(this)}else a.apply(this,arguments)}});var g=angular.module("angularFileUpload",[]);g.version="2.0.3",g.service("$upload",["$http","$q","$timeout",function(a,b,c){function d(d){d.method=d.method||"POST",d.headers=d.headers||{},d.transformRequest=d.transformRequest||function(b,c){return window.ArrayBuffer&&b instanceof window.ArrayBuffer?b:a.defaults.transformRequest[0](b,c)};var e=b.defer(),f=e.promise;return d.headers.__setXHR_=function(){return function(a){a&&(d.__XHR=a,d.xhrFn&&d.xhrFn(a),a.upload.addEventListener("progress",function(a){a.config=d,e.notify?e.notify(a):f.progress_fn&&c(function(){f.progress_fn(a)})},!1),a.upload.addEventListener("load",function(a){a.lengthComputable&&(a.config=d,e.notify?e.notify(a):f.progress_fn&&c(function(){f.progress_fn(a)}))},!1))}},a(d).then(function(a){e.resolve(a)},function(a){e.reject(a)},function(a){e.notify(a)}),f.success=function(a){return f.then(function(b){a(b.data,b.status,b.headers,d)}),f},f.error=function(a){return f.then(null,function(b){a(b.data,b.status,b.headers,d)}),f},f.progress=function(a){return f.progress_fn=a,f.then(null,null,function(b){a(b)}),f},f.abort=function(){return d.__XHR&&c(function(){d.__XHR.abort()}),f},f.xhr=function(a){return d.xhrFn=function(b){return function(){b&&b.apply(f,arguments),a.apply(f,arguments)}}(d.xhrFn),f},f}this.upload=function(b){b.headers=b.headers||{},b.headers["Content-Type"]=void 0,b.transformRequest=b.transformRequest||a.defaults.transformRequest;var c=new FormData,e=b.transformRequest,f=b.data;return b.transformRequest=function(a,c){if(f)if(b.formDataAppender)for(var d in f){var g=f[d];b.formDataAppender(a,d,g)}else for(var d in f){var g=f[d];if("function"==typeof e)g=e(g,c);else for(var h=0;h-1&&a.apply(this,[b,"_fix_for_ie_crossdomain__",e])}}}),a("getResponseHeader",function(a){return function(b){return this.__fileApiXHR&&this.__fileApiXHR.getResponseHeader?this.__fileApiXHR.getResponseHeader(b):null==a?null:a.apply(this,[b])}}),a("getAllResponseHeaders",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.getAllResponseHeaders?this.__fileApiXHR.getAllResponseHeaders():null==a?null:a.apply(this)}}),a("abort",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.abort?this.__fileApiXHR.abort():null==a?null:a.apply(this)}}),a("setRequestHeader",function(a){return function(b,c){if("__setXHR_"===b){d(this);var e=c(this);e instanceof Function&&e(this)}else this.__requestHeaders=this.__requestHeaders||{},this.__requestHeaders[b]=c,a.apply(this,arguments)}}),a("send",function(a){return function(){var d=this;if(arguments[0]&&arguments[0].__isFileAPIShim){var e=arguments[0],f={url:d.__url,jsonp:!1,cache:!0,complete:function(a,c){d.__completed=!0,!a&&d.__listeners.load&&d.__listeners.load({type:"load",loaded:d.__loaded,total:d.__total,target:d,lengthComputable:!0}),!a&&d.__listeners.loadend&&d.__listeners.loadend({type:"loadend",loaded:d.__loaded,total:d.__total,target:d,lengthComputable:!0}),"abort"===a&&d.__listeners.abort&&d.__listeners.abort({type:"abort",loaded:d.__loaded,total:d.__total,target:d,lengthComputable:!0}),void 0!==c.status&&b(d,"status",function(){return 0==c.status&&a&&"abort"!==a?500:c.status}),void 0!==c.statusText&&b(d,"statusText",function(){return c.statusText}),b(d,"readyState",function(){return 4}),void 0!==c.response&&b(d,"response",function(){return c.response});var e=c.responseText||(a&&0==c.status&&"abort"!==a?a:void 0);b(d,"responseText",function(){return e}),b(d,"response",function(){return e}),a&&b(d,"err",function(){return a}),d.__fileApiXHR=c,d.onreadystatechange&&d.onreadystatechange(),d.onload&&d.onload()},fileprogress:function(a){if(a.target=d,d.__listeners.progress&&d.__listeners.progress(a),d.__total=a.total,d.__loaded=a.loaded,a.total===a.loaded){var b=this;setTimeout(function(){d.__completed||(d.getAllResponseHeaders=function(){},b.complete(null,{status:204,statusText:"No Content"}))},1e4)}},headers:d.__requestHeaders};f.data={},f.files={};for(var g=0;g',d=d.firstChild;var e=a.parentNode;e.insertBefore(d,a),e.removeChild(a),d.appendChild(a)}else b.addClass("js-fileapi-wrapper"),b.attr("ng-file-generated-elem")&&((""===b.parent().css("position")||"static"===b.parent().css("position"))&&b.parent().css("position","relative"),b.css("top",0).css("bottom",0).css("left",0).css("right",0).css("width","100%").css("height","100%").css("padding",0).css("margin",0),b.parent().unbind("click",b.parent().__afu_fileClickDelegate__))},f=function(a){return function(b){for(var c=FileAPI.getFiles(b),d=0;d-1){b=f.substring(0,e+1);break}null==FileAPI.staticPath&&(FileAPI.staticPath=b),g.setAttribute("src",a||b+"FileAPI.js"),document.getElementsByTagName("head")[0].appendChild(g),FileAPI.hasFlash=c()}}(),FileAPI.disableFileInput=function(a,b){b?a.removeClass("js-fileapi-wrapper"):a.addClass("js-fileapi-wrapper")}}window.FileReader||(window.FileReader=function(){var a=this,b=!1;this.listeners={},this.addEventListener=function(b,c){a.listeners[b]=a.listeners[b]||[],a.listeners[b].push(c)},this.removeEventListener=function(b,c){a.listeners[b]&&a.listeners[b].splice(a.listeners[b].indexOf(c),1)},this.dispatchEvent=function(b){var c=a.listeners[b.type];if(c)for(var d=0;d - * @version 2.0.2 + * @version 2.0.3 */ (function() { diff --git a/dist/angular-file-upload-shim.min.js b/dist/angular-file-upload-shim.min.js index 98cd7728..b5bdde41 100644 --- a/dist/angular-file-upload-shim.min.js +++ b/dist/angular-file-upload-shim.min.js @@ -1,2 +1,2 @@ -/*! 2.0.2 */ +/*! 2.0.3 */ !function(){function a(a,b){window.XMLHttpRequest.prototype[a]=b(window.XMLHttpRequest.prototype[a])}function b(a,b,c){try{Object.defineProperty(a,b,{get:c})}catch(d){}}var c=function(){try{var a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if(a)return!0}catch(b){if(void 0!=navigator.mimeTypes["application/x-shockwave-flash"])return!0}return!1};if(window.XMLHttpRequest&&!window.FormData||window.FileAPI&&FileAPI.forceLoad){var d=function(a){if(!a.__listeners){a.upload||(a.upload={}),a.__listeners=[];var b=a.upload.addEventListener;a.upload.addEventListener=function(c,d){a.__listeners[c]=d,b&&b.apply(this,arguments)}}};a("open",function(a){return function(b,c,e){d(this),this.__url=c;try{a.apply(this,[b,c,e])}catch(f){f.message.indexOf("Access is denied")>-1&&a.apply(this,[b,"_fix_for_ie_crossdomain__",e])}}}),a("getResponseHeader",function(a){return function(b){return this.__fileApiXHR&&this.__fileApiXHR.getResponseHeader?this.__fileApiXHR.getResponseHeader(b):null==a?null:a.apply(this,[b])}}),a("getAllResponseHeaders",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.getAllResponseHeaders?this.__fileApiXHR.getAllResponseHeaders():null==a?null:a.apply(this)}}),a("abort",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.abort?this.__fileApiXHR.abort():null==a?null:a.apply(this)}}),a("setRequestHeader",function(a){return function(b,c){if("__setXHR_"===b){d(this);var e=c(this);e instanceof Function&&e(this)}else this.__requestHeaders=this.__requestHeaders||{},this.__requestHeaders[b]=c,a.apply(this,arguments)}}),a("send",function(a){return function(){var d=this;if(arguments[0]&&arguments[0].__isFileAPIShim){var e=arguments[0],f={url:d.__url,jsonp:!1,cache:!0,complete:function(a,c){d.__completed=!0,!a&&d.__listeners.load&&d.__listeners.load({type:"load",loaded:d.__loaded,total:d.__total,target:d,lengthComputable:!0}),!a&&d.__listeners.loadend&&d.__listeners.loadend({type:"loadend",loaded:d.__loaded,total:d.__total,target:d,lengthComputable:!0}),"abort"===a&&d.__listeners.abort&&d.__listeners.abort({type:"abort",loaded:d.__loaded,total:d.__total,target:d,lengthComputable:!0}),void 0!==c.status&&b(d,"status",function(){return 0==c.status&&a&&"abort"!==a?500:c.status}),void 0!==c.statusText&&b(d,"statusText",function(){return c.statusText}),b(d,"readyState",function(){return 4}),void 0!==c.response&&b(d,"response",function(){return c.response});var e=c.responseText||(a&&0==c.status&&"abort"!==a?a:void 0);b(d,"responseText",function(){return e}),b(d,"response",function(){return e}),a&&b(d,"err",function(){return a}),d.__fileApiXHR=c,d.onreadystatechange&&d.onreadystatechange(),d.onload&&d.onload()},fileprogress:function(a){if(a.target=d,d.__listeners.progress&&d.__listeners.progress(a),d.__total=a.total,d.__loaded=a.loaded,a.total===a.loaded){var b=this;setTimeout(function(){d.__completed||(d.getAllResponseHeaders=function(){},b.complete(null,{status:204,statusText:"No Content"}))},1e4)}},headers:d.__requestHeaders};f.data={},f.files={};for(var g=0;g',d=d.firstChild;var e=a.parentNode;e.insertBefore(d,a),e.removeChild(a),d.appendChild(a)}else b.addClass("js-fileapi-wrapper"),b.attr("ng-file-generated-elem")&&((""===b.parent().css("position")||"static"===b.parent().css("position"))&&b.parent().css("position","relative"),b.css("top",0).css("bottom",0).css("left",0).css("right",0).css("width","100%").css("height","100%").css("padding",0).css("margin",0),b.parent().unbind("click",b.parent().__afu_fileClickDelegate__))},f=function(a){return function(b){for(var c=FileAPI.getFiles(b),d=0;d-1){b=f.substring(0,e+1);break}null==FileAPI.staticPath&&(FileAPI.staticPath=b),g.setAttribute("src",a||b+"FileAPI.js"),document.getElementsByTagName("head")[0].appendChild(g),FileAPI.hasFlash=c()}}(),FileAPI.disableFileInput=function(a,b){b?a.removeClass("js-fileapi-wrapper"):a.addClass("js-fileapi-wrapper")}}window.FileReader||(window.FileReader=function(){var a=this,b=!1;this.listeners={},this.addEventListener=function(b,c){a.listeners[b]=a.listeners[b]||[],a.listeners[b].push(c)},this.removeEventListener=function(b,c){a.listeners[b]&&a.listeners[b].splice(a.listeners[b].indexOf(c),1)},this.dispatchEvent=function(b){var c=a.listeners[b.type];if(c)for(var d=0;d - * @version 2.0.2 + * @version 2.0.3 */ (function() { @@ -26,7 +26,7 @@ if (window.XMLHttpRequest && !window.XMLHttpRequest.__isFileAPIShim) { } var angularFileUpload = angular.module('angularFileUpload', []); -angularFileUpload.version = '2.0.2'; +angularFileUpload.version = '2.0.3'; angularFileUpload.service('$upload', ['$http', '$q', '$timeout', function($http, $q, $timeout) { function sendHttp(config) { config.method = config.method || 'POST'; @@ -193,8 +193,17 @@ function handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout) { } if (scope.resetOnClick() != false) { elem.bind('click', function(evt) { - this.value = null; - updateModel([], attr, ngModel, scope, evt); + if (elem[0].value) { + updateModel([], attr, ngModel, scope, evt); + } + elem[0].value = null; + }); + } + if (ngModel) { + scope.$parent.$watch(attr['ngModel'], function(val) { + if (val == null) { + elem[0].value = null; + } }); } if (attr['ngFileSelect'] != '') { diff --git a/dist/angular-file-upload.min.js b/dist/angular-file-upload.min.js index 27356329..d9c7a005 100644 --- a/dist/angular-file-upload.min.js +++ b/dist/angular-file-upload.min.js @@ -1,2 +1,2 @@ -/*! 2.0.2 */ -!function(){function a(a,b){window.XMLHttpRequest.prototype[a]=b(window.XMLHttpRequest.prototype[a])}function b(a,b,c,d,e,f){function g(a,b,c,d,e){f(function(){for(var b=[],g=0;g');c.multiple&&h.attr("multiple",c.multiple),c.accept&&h.attr("accept",c.accept),h.css("width","1px").css("height","1px").css("opacity",0).css("position","absolute").css("filter","alpha(opacity=0)").css("padding",0).css("margin",0).css("overflow","hidden").attr("tabindex","-1").attr("ng-file-generated-elem",!0),b.append(h),b.__afu_fileClickDelegate__=function(){h[0].click()},b.bind("click",b.__afu_fileClickDelegate__),b.css("overflow","hidden"),b=h}0!=a.resetOnClick()&&b.bind("click",function(b){this.value=null,g([],c,d,a,b)}),""!=c.ngFileSelect&&(a.change=a.select),b.bind("change",function(b){var e;e=b.__files_||b.target.files,g(e,c,d,a,b)})}function c(a,b,c,g,h,i,j){function k(a,b,c){var d=!0;if(q){var e=c.dataTransfer.items;if(null!=e)for(var f=0;f0&&"file"!=j.protocol())for(var m=0;m0)break}else{var p=a.dataTransfer.files;if(null!=p)for(var m=0;m0));m++);}var r=0;!function t(a){i(function(){if(s)10*r++<2e4&&t(10);else{if(!d&&h.length>1){for(var a=0;"directory"==h[a].type;)a++;h=[h[a]]}b(h,k)}},a||0)}();var s=0}g&&g.$setViewValue("");var m=d();if(c.dropAvailable&&i(function(){a.dropAvailable=m}),!m)return 0!=a.hideOnDropNotAvailable()&&b.css("display","none"),void 0;var n=null,o=a.stopPropagation(),p=1,q=null==c.accept?null:new RegExp(f(c.accept));b[0].addEventListener("dragover",function(d){d.preventDefault(),o&&d.stopPropagation(),i.cancel(n),a.actualDragOverClass||(a.actualDragOverClass=k(a,c,d)),b.addClass(a.actualDragOverClass)},!1),b[0].addEventListener("dragenter",function(a){a.preventDefault(),o&&a.stopPropagation()},!1),b[0].addEventListener("dragleave",function(){n=i(function(){b.removeClass(a.actualDragOverClass),a.actualDragOverClass=null},p||1)},!1),""!=c.ngFileDrop&&(a.change=a.drop),b[0].addEventListener("drop",function(d){d.preventDefault(),o&&d.stopPropagation(),b.removeClass(a.actualDragOverClass),a.actualDragOverClass=null,l(d,function(b,e){g&&(a.fileModel=b,g&&g.$setViewValue(null!=b&&0==b.length?"":b)),c.ngFileRejectedModel&&(a.fileRejectedModel=e),i(function(){a.change({$files:b,$rejectedFiles:e,$event:d})})},0!=a.allowDir(),c.multiple)},!1)}function d(){var a=document.createElement("div");return"draggable"in a&&"ondrop"in a}function e(a){return/^[\000-\177]*$/.test(a)}function f(a){if(a.length>2&&"/"===a[0]&&"/"===a[a.length-1])return a.substring(1,a.length-1);var b=a.split(","),c="";if(b.length>1)for(var d=0;d|:\\-]","g"),"\\$&")+"$",c=c.replace(/\\\*/g,".*").replace(/\\\?/g,".");return c}window.XMLHttpRequest&&!window.XMLHttpRequest.__isFileAPIShim&&a("setRequestHeader",function(a){return function(b,c){if("__setXHR_"===b){var d=c(this);d instanceof Function&&d(this)}else a.apply(this,arguments)}});var g=angular.module("angularFileUpload",[]);g.version="2.0.2",g.service("$upload",["$http","$q","$timeout",function(a,b,c){function d(d){d.method=d.method||"POST",d.headers=d.headers||{},d.transformRequest=d.transformRequest||function(b,c){return window.ArrayBuffer&&b instanceof window.ArrayBuffer?b:a.defaults.transformRequest[0](b,c)};var e=b.defer(),f=e.promise;return d.headers.__setXHR_=function(){return function(a){a&&(d.__XHR=a,d.xhrFn&&d.xhrFn(a),a.upload.addEventListener("progress",function(a){a.config=d,e.notify?e.notify(a):f.progress_fn&&c(function(){f.progress_fn(a)})},!1),a.upload.addEventListener("load",function(a){a.lengthComputable&&(a.config=d,e.notify?e.notify(a):f.progress_fn&&c(function(){f.progress_fn(a)}))},!1))}},a(d).then(function(a){e.resolve(a)},function(a){e.reject(a)},function(a){e.notify(a)}),f.success=function(a){return f.then(function(b){a(b.data,b.status,b.headers,d)}),f},f.error=function(a){return f.then(null,function(b){a(b.data,b.status,b.headers,d)}),f},f.progress=function(a){return f.progress_fn=a,f.then(null,null,function(b){a(b)}),f},f.abort=function(){return d.__XHR&&c(function(){d.__XHR.abort()}),f},f.xhr=function(a){return d.xhrFn=function(b){return function(){b&&b.apply(f,arguments),a.apply(f,arguments)}}(d.xhrFn),f},f}this.upload=function(b){b.headers=b.headers||{},b.headers["Content-Type"]=void 0,b.transformRequest=b.transformRequest||a.defaults.transformRequest;var c=new FormData,e=b.transformRequest,f=b.data;return b.transformRequest=function(a,c){if(f)if(b.formDataAppender)for(var d in f){var g=f[d];b.formDataAppender(a,d,g)}else for(var d in f){var g=f[d];if("function"==typeof e)g=e(g,c);else for(var h=0;h');c.multiple&&h.attr("multiple",c.multiple),c.accept&&h.attr("accept",c.accept),h.css("width","1px").css("height","1px").css("opacity",0).css("position","absolute").css("filter","alpha(opacity=0)").css("padding",0).css("margin",0).css("overflow","hidden").attr("tabindex","-1").attr("ng-file-generated-elem",!0),b.append(h),b.__afu_fileClickDelegate__=function(){h[0].click()},b.bind("click",b.__afu_fileClickDelegate__),b.css("overflow","hidden"),b=h}0!=a.resetOnClick()&&b.bind("click",function(e){b[0].value&&g([],c,d,a,e),b[0].value=null}),d&&a.$parent.$watch(c.ngModel,function(a){null==a&&(b[0].value=null)}),""!=c.ngFileSelect&&(a.change=a.select),b.bind("change",function(b){var e;e=b.__files_||b.target.files,g(e,c,d,a,b)})}function c(a,b,c,g,h,i,j){function k(a,b,c){var d=!0;if(q){var e=c.dataTransfer.items;if(null!=e)for(var f=0;f0&&"file"!=j.protocol())for(var m=0;m0)break}else{var p=a.dataTransfer.files;if(null!=p)for(var m=0;m0));m++);}var r=0;!function t(a){i(function(){if(s)10*r++<2e4&&t(10);else{if(!d&&h.length>1){for(var a=0;"directory"==h[a].type;)a++;h=[h[a]]}b(h,k)}},a||0)}();var s=0}g&&g.$setViewValue("");var m=d();if(c.dropAvailable&&i(function(){a.dropAvailable=m}),!m)return 0!=a.hideOnDropNotAvailable()&&b.css("display","none"),void 0;var n=null,o=a.stopPropagation(),p=1,q=null==c.accept?null:new RegExp(f(c.accept));b[0].addEventListener("dragover",function(d){d.preventDefault(),o&&d.stopPropagation(),i.cancel(n),a.actualDragOverClass||(a.actualDragOverClass=k(a,c,d)),b.addClass(a.actualDragOverClass)},!1),b[0].addEventListener("dragenter",function(a){a.preventDefault(),o&&a.stopPropagation()},!1),b[0].addEventListener("dragleave",function(){n=i(function(){b.removeClass(a.actualDragOverClass),a.actualDragOverClass=null},p||1)},!1),""!=c.ngFileDrop&&(a.change=a.drop),b[0].addEventListener("drop",function(d){d.preventDefault(),o&&d.stopPropagation(),b.removeClass(a.actualDragOverClass),a.actualDragOverClass=null,l(d,function(b,e){g&&(a.fileModel=b,g&&g.$setViewValue(null!=b&&0==b.length?"":b)),c.ngFileRejectedModel&&(a.fileRejectedModel=e),i(function(){a.change({$files:b,$rejectedFiles:e,$event:d})})},0!=a.allowDir(),c.multiple)},!1)}function d(){var a=document.createElement("div");return"draggable"in a&&"ondrop"in a}function e(a){return/^[\000-\177]*$/.test(a)}function f(a){if(a.length>2&&"/"===a[0]&&"/"===a[a.length-1])return a.substring(1,a.length-1);var b=a.split(","),c="";if(b.length>1)for(var d=0;d|:\\-]","g"),"\\$&")+"$",c=c.replace(/\\\*/g,".*").replace(/\\\?/g,".");return c}window.XMLHttpRequest&&!window.XMLHttpRequest.__isFileAPIShim&&a("setRequestHeader",function(a){return function(b,c){if("__setXHR_"===b){var d=c(this);d instanceof Function&&d(this)}else a.apply(this,arguments)}});var g=angular.module("angularFileUpload",[]);g.version="2.0.3",g.service("$upload",["$http","$q","$timeout",function(a,b,c){function d(d){d.method=d.method||"POST",d.headers=d.headers||{},d.transformRequest=d.transformRequest||function(b,c){return window.ArrayBuffer&&b instanceof window.ArrayBuffer?b:a.defaults.transformRequest[0](b,c)};var e=b.defer(),f=e.promise;return d.headers.__setXHR_=function(){return function(a){a&&(d.__XHR=a,d.xhrFn&&d.xhrFn(a),a.upload.addEventListener("progress",function(a){a.config=d,e.notify?e.notify(a):f.progress_fn&&c(function(){f.progress_fn(a)})},!1),a.upload.addEventListener("load",function(a){a.lengthComputable&&(a.config=d,e.notify?e.notify(a):f.progress_fn&&c(function(){f.progress_fn(a)}))},!1))}},a(d).then(function(a){e.resolve(a)},function(a){e.reject(a)},function(a){e.notify(a)}),f.success=function(a){return f.then(function(b){a(b.data,b.status,b.headers,d)}),f},f.error=function(a){return f.then(null,function(b){a(b.data,b.status,b.headers,d)}),f},f.progress=function(a){return f.progress_fn=a,f.then(null,null,function(b){a(b)}),f},f.abort=function(){return d.__XHR&&c(function(){d.__XHR.abort()}),f},f.xhr=function(a){return d.xhrFn=function(b){return function(){b&&b.apply(f,arguments),a.apply(f,arguments)}}(d.xhrFn),f},f}this.upload=function(b){b.headers=b.headers||{},b.headers["Content-Type"]=void 0,b.transformRequest=b.transformRequest||a.defaults.transformRequest;var c=new FormData,e=b.transformRequest,f=b.data;return b.transformRequest=function(a,c){if(f)if(b.formDataAppender)for(var d in f){var g=f[d];b.formDataAppender(a,d,g)}else for(var d in f){var g=f[d];if("function"==typeof e)g=e(g,c);else for(var h=0;h angular-file-upload Angular file upload - 2.0.2 + 2.0.3 Danial Farid, Georgios Diamantopoulos (nuget package) Danial Farid https://github.com/danialfarid/angular-file-upload/blob/master/LICENSE diff --git a/package.json b/package.json index 296341a0..40842f80 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-file-upload", - "version": "2.0.2", + "version": "2.0.3", "devDependencies": { "grunt": "~0.4.1", "grunt-contrib-uglify": "~0.2.7",