diff --git a/.gitignore b/.gitignore index 0e491efe..3b58c6f1 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ Thumbs.db /target/* classes/ ._* -/node_modules \ No newline at end of file +/node_modules +*.jar \ No newline at end of file diff --git a/demo/.classpath b/demo/.classpath index 276755fc..86c25dd7 100644 --- a/demo/.classpath +++ b/demo/.classpath @@ -1,8 +1,8 @@ - + diff --git a/demo/war/WEB-INF/lib/appengine-api-labs.jar b/demo/war/WEB-INF/lib/appengine-api-labs.jar index 453391fc..3a15b875 100644 Binary files a/demo/war/WEB-INF/lib/appengine-api-labs.jar and b/demo/war/WEB-INF/lib/appengine-api-labs.jar differ diff --git a/demo/war/WEB-INF/lib/appengine-endpoints.jar b/demo/war/WEB-INF/lib/appengine-endpoints.jar index a1e91d1c..b34d5efe 100644 Binary files a/demo/war/WEB-INF/lib/appengine-endpoints.jar and b/demo/war/WEB-INF/lib/appengine-endpoints.jar differ diff --git a/demo/war/WEB-INF/lib/appengine-jsr107cache-1.8.6.jar b/demo/war/WEB-INF/lib/appengine-jsr107cache-1.8.6.jar deleted file mode 100644 index 675f1f80..00000000 Binary files a/demo/war/WEB-INF/lib/appengine-jsr107cache-1.8.6.jar and /dev/null differ diff --git a/demo/war/index.html b/demo/war/index.html index e3e91d0e..e6db5d60 100644 --- a/demo/war/index.html +++ b/demo/war/index.html @@ -77,6 +77,6 @@

-
Last update: 2014-02-19
+
Last update: 2014-03-24
diff --git a/demo/war/js/angular-file-upload-shim.js b/demo/war/js/angular-file-upload-shim.js index 3c32217b..1eb2877a 100644 --- a/demo/war/js/angular-file-upload-shim.js +++ b/demo/war/js/angular-file-upload-shim.js @@ -45,13 +45,9 @@ if (window.XMLHttpRequest) { xhr.__requestHeaders = []; xhr.open = (function(orig) { if (!xhr.upload) xhr.upload = {}; + xhr.__listeners = []; xhr.upload.addEventListener = function(t, fn, b) { - if (t === 'progress') { - xhr.__progress = fn; - } - if (t === 'load') { - xhr.__load = fn; - } + xhr.__listeners[t] = fn; }; return function(m, url, b) { orig.apply(xhr, [m, url, b]); @@ -93,7 +89,12 @@ if (window.XMLHttpRequest) { var config = { url: xhr.__url, complete: function(err, fileApiXHR) { - if (!err) xhr.__load({type: 'load', loaded: xhr.__total, total: xhr.__total, target: xhr, lengthComputable: true}); + if (!err && xhr.__listeners['load']) + xhr.__listeners['load']({type: 'load', loaded: xhr.__loaded, total: xhr.__total, target: xhr, lengthComputable: true}); + if (!err && xhr.__listeners['loadend']) + xhr.__listeners['loadend']({type: 'loadend', loaded: xhr.__loaded, total: xhr.__total, target: xhr, lengthComputable: true}); + if (err === 'abort' && xhr.__listeners['abort']) + xhr.__listeners['abort']({type: 'abort', loaded: xhr.__loaded, total: xhr.__total, target: xhr, lengthComputable: true}); if (fileApiXHR.status !== undefined) Object.defineProperty(xhr, 'status', {get: function() {return fileApiXHR.status}}); if (fileApiXHR.statusText !== undefined) Object.defineProperty(xhr, 'statusText', {get: function() {return fileApiXHR.statusText}}); Object.defineProperty(xhr, 'readyState', {get: function() {return 4}}); @@ -104,8 +105,9 @@ if (window.XMLHttpRequest) { }, progress: function(e) { e.target = xhr; - xhr.__progress(e); + xhr.__listeners['progress'] && xhr.__listeners['progress'](e); xhr.__total = e.total; + xhr.__loaded = e.loaded; }, headers: xhr.__requestHeaders } diff --git a/demo/war/js/angular-file-upload.js b/demo/war/js/angular-file-upload.js index 09f28d36..67754366 100644 --- a/demo/war/js/angular-file-upload.js +++ b/demo/war/js/angular-file-upload.js @@ -11,17 +11,18 @@ angularFileUpload.service('$upload', ['$http', '$timeout', function($http, $time function sendHttp(config) { config.method = config.method || 'POST'; config.headers = config.headers || {}; - config.transformRequest = config.transformRequest || function(data) { - if (window.ArrayBuffer && data instanceof ArrayBuffer) { + config.transformRequest = config.transformRequest || function(data, headersGetter) { + if (window.ArrayBuffer && data instanceof window.ArrayBuffer) { return data; } - return $http.defaults.transformRequest[0](data); + return $http.defaults.transformRequest[0](data, headersGetter); }; - + if (window.XMLHttpRequest.__isShim) { config.headers['__setXHR_'] = function() { return function(xhr) { config.__XHR = xhr; + config.xhrFn && config.xhrFn(xhr); xhr.upload.addEventListener('progress', function(e) { if (config.progress) { $timeout(function() { @@ -40,13 +41,13 @@ angularFileUpload.service('$upload', ['$http', '$timeout', function($http, $time } }; } - + var promise = $http(config); - + promise.progress = function(fn) { config.progress = fn; return promise; - }; + }; promise.abort = function() { if (config.__XHR) { $timeout(function() { @@ -54,62 +55,78 @@ angularFileUpload.service('$upload', ['$http', '$timeout', function($http, $time }); } return promise; - }; + }; + promise.xhr = function(fn) { + config.xhrFn = fn; + return promise; + }; promise.then = (function(promise, origThen) { return function(s, e, p) { config.progress = p || config.progress; var result = origThen.apply(promise, [s, e, p]); result.abort = promise.abort; result.progress = promise.progress; + result.xhr = promise.xhr; return result; }; })(promise, promise.then); return promise; } + this.upload = function(config) { config.headers = config.headers || {}; config.headers['Content-Type'] = undefined; config.transformRequest = config.transformRequest || $http.defaults.transformRequest; var formData = new FormData(); - var i; if (config.data) { - for (var key in config.data) { - var val = config.data[key]; - if (!config.formDataAppender) { - if (typeof config.transformRequest == 'function') { - val = config.transformRequest(val); - } else { - for (i = 0; i < config.transformRequest.length; i++) { - var fn = config.transformRequest[i]; - if (typeof fn == 'function') { - val = fn(val); + if (config.formDataAppender) { + for (var key in config.data) { + var val = config.data[key]; + config.formDataAppender(formData, key, val); + } + config.transformRequest = angular.identity; + } else { + var origTransformRequest = config.transformRequest; + var origData = config.data; + config.transformRequest = function(formData, headerGetter) { + for (var key in origData) { + var val = origData[key]; + if (typeof origTransformRequest == 'function') { + val = origTransformRequest(val, headerGetter); + } else { + for (var i = 0; i < origTransformRequest.length; i++) { + var transformFn = origTransformRequest[i]; + if (typeof transformFn == 'function') { + val = transformFn(val, headerGetter); + } } } + formData.append(key, val); } - formData.append(key, val); - } else { - config.formDataAppender(formData, key, val); - } + return formData; + }; } } - config.transformRequest = angular.identity; - - var fileFormName = config.fileFormDataName || 'file'; - - if (Object.prototype.toString.call(config.file) === '[object Array]') { - var isFileFormNameString = Object.prototype.toString.call(fileFormName) === '[object String]'; - for (i = 0; i < config.file.length; i++) { - formData.append(isFileFormNameString ? fileFormName + i : fileFormName[i], config.file[i], config.file[i].name); + + if (config.file != null) { + var fileFormName = config.fileFormDataName || 'file'; + + if (Object.prototype.toString.call(config.file) === '[object Array]') { + var isFileFormNameString = Object.prototype.toString.call(fileFormName) === '[object String]'; + for (var i = 0; i < config.file.length; i++) { + formData.append(isFileFormNameString ? fileFormName + i : fileFormName[i], config.file[i], config.file[i].name); + } + } else { + formData.append(fileFormName, config.file, config.file.name); } - } else { - formData.append(fileFormName, config.file, config.file.name); } - + config.data = formData; - + return sendHttp(config); }; + this.http = function(config) { return sendHttp(config); } diff --git a/demo/war/js/upload.js b/demo/war/js/upload.js index 5a6c7b2d..c1203a4b 100644 --- a/demo/war/js/upload.js +++ b/demo/war/js/upload.js @@ -56,7 +56,7 @@ var MyCtrl = [ '$scope', '$http', '$timeout', '$upload', function($scope, $http $scope.upload[index] = $upload.upload({ url : 'upload', method: $scope.httpMethod, - headers: {'myHeaderKey': 'myHeaderVal'}, + headers: {'my-header': 'my-header-value'}, data : { myModel : $scope.myModel }, @@ -69,12 +69,17 @@ var MyCtrl = [ '$scope', '$http', '$timeout', '$upload', function($scope, $http fd.append(key, val); } }, */ + /* transformRequest: [function(val, h) { + console.log(val, h('my-header')); return val + 'aaaaa'; + }], */ file: $scope.selectedFiles[index], fileFormDataName: 'myFile' }).then(function(response) { $scope.uploadResult.push(response.data); }, null, function(evt) { $scope.progress[index] = parseInt(100.0 * evt.loaded / evt.total); + }).xhr(function(xhr){ + xhr.upload.addEventListener('abort', function(){console.log('aborted complete')}, false); }); } else { var fileReader = new FileReader(); diff --git a/dist/angular-file-upload-html5-shim.js b/dist/angular-file-upload-html5-shim.js index 9796dd85..9a005329 100644 --- a/dist/angular-file-upload-html5-shim.js +++ b/dist/angular-file-upload-html5-shim.js @@ -1,7 +1,7 @@ /**! * AngularJS file upload shim for angular XHR HTML5 browsers * @author Danial - * @version 1.2.9 + * @version 1.2.10 */ if (window.XMLHttpRequest) { if (window.FormData) { diff --git a/dist/angular-file-upload-html5-shim.min.js b/dist/angular-file-upload-html5-shim.min.js index d61705ed..03177346 100644 --- a/dist/angular-file-upload-html5-shim.min.js +++ b/dist/angular-file-upload-html5-shim.min.js @@ -1,2 +1,2 @@ -/*! 1.2.9 */ +/*! 1.2.10 */ window.XMLHttpRequest&&window.FormData&&(XMLHttpRequest=function(a){return function(){var b=new a;return b.setRequestHeader=function(a){return function(c,d){if("__setXHR_"===c){var e=d(b);e instanceof Function&&e(b)}else a.apply(b,arguments)}}(b.setRequestHeader),b}}(XMLHttpRequest),window.XMLHttpRequest.__isShim=!0); \ No newline at end of file diff --git a/dist/angular-file-upload-shim.js b/dist/angular-file-upload-shim.js index 13604c5d..2a81afdc 100644 --- a/dist/angular-file-upload-shim.js +++ b/dist/angular-file-upload-shim.js @@ -1,7 +1,7 @@ /**! * AngularJS file upload shim for HTML5 FormData * @author Danial - * @version 1.2.9 + * @version 1.2.10 */ (function() { @@ -45,13 +45,9 @@ if (window.XMLHttpRequest) { xhr.__requestHeaders = []; xhr.open = (function(orig) { if (!xhr.upload) xhr.upload = {}; + xhr.__listeners = []; xhr.upload.addEventListener = function(t, fn, b) { - if (t === 'progress') { - xhr.__progress = fn; - } - if (t === 'load') { - xhr.__load = fn; - } + xhr.__listeners[t] = fn; }; return function(m, url, b) { orig.apply(xhr, [m, url, b]); @@ -93,7 +89,12 @@ if (window.XMLHttpRequest) { var config = { url: xhr.__url, complete: function(err, fileApiXHR) { - if (!err) xhr.__load({type: 'load', loaded: xhr.__total, total: xhr.__total, target: xhr, lengthComputable: true}); + if (!err && xhr.__listeners['load']) + xhr.__listeners['load']({type: 'load', loaded: xhr.__loaded, total: xhr.__total, target: xhr, lengthComputable: true}); + if (!err && xhr.__listeners['loadend']) + xhr.__listeners['loadend']({type: 'loadend', loaded: xhr.__loaded, total: xhr.__total, target: xhr, lengthComputable: true}); + if (err === 'abort' && xhr.__listeners['abort']) + xhr.__listeners['abort']({type: 'abort', loaded: xhr.__loaded, total: xhr.__total, target: xhr, lengthComputable: true}); if (fileApiXHR.status !== undefined) Object.defineProperty(xhr, 'status', {get: function() {return fileApiXHR.status}}); if (fileApiXHR.statusText !== undefined) Object.defineProperty(xhr, 'statusText', {get: function() {return fileApiXHR.statusText}}); Object.defineProperty(xhr, 'readyState', {get: function() {return 4}}); @@ -104,8 +105,9 @@ if (window.XMLHttpRequest) { }, progress: function(e) { e.target = xhr; - xhr.__progress(e); + xhr.__listeners['progress'] && xhr.__listeners['progress'](e); xhr.__total = e.total; + xhr.__loaded = e.loaded; }, headers: xhr.__requestHeaders } diff --git a/dist/angular-file-upload-shim.min.js b/dist/angular-file-upload-shim.min.js index 45616d73..4af35dd6 100644 --- a/dist/angular-file-upload-shim.min.js +++ b/dist/angular-file-upload-shim.min.js @@ -1,2 +1,2 @@ -/*! 1.2.9 */ -!function(){var a=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.XMLHttpRequest=function(a){return function(){var b=new a;return b.setRequestHeader=function(a){return function(c,d){if("__setXHR_"===c){var e=d(b);e instanceof Function&&e(b)}else a.apply(b,arguments)}}(b.setRequestHeader),b}}(window.XMLHttpRequest):(window.XMLHttpRequest=function(b){return function(){var c=new b,d=c.send;return c.__requestHeaders=[],c.open=function(a){return c.upload||(c.upload={}),c.upload.addEventListener=function(a,b){"progress"===a&&(c.__progress=b),"load"===a&&(c.__load=b)},function(b,d,e){a.apply(c,[b,d,e]),c.__url=d}}(c.open),c.getResponseHeader=function(a){return function(b){return c.__fileApiXHR?c.__fileApiXHR.getResponseHeader(b):a.apply(c,[b])}}(c.getResponseHeader),c.getAllResponseHeaders=function(a){return function(){return c.__fileApiXHR?c.__fileApiXHR.getAllResponseHeaders():a.apply(c)}}(c.getAllResponseHeaders),c.abort=function(a){return function(){return c.__fileApiXHR?c.__fileApiXHR.abort():null==a?null:a.apply(c)}}(c.abort),c.setRequestHeader=function(a){return function(b,d){if("__setXHR_"===b){var e=d(c);e instanceof Function&&e(c)}else a.apply(c,arguments)}}(c.setRequestHeader),c.send=function(){if(arguments[0]&&arguments[0].__isShim){var b=arguments[0],e={url:c.__url,complete:function(a,b){a||c.__load({type:"load",loaded:c.__total,total:c.__total,target:c,lengthComputable:!0}),void 0!==b.status&&Object.defineProperty(c,"status",{get:function(){return b.status}}),void 0!==b.statusText&&Object.defineProperty(c,"statusText",{get:function(){return b.statusText}}),Object.defineProperty(c,"readyState",{get:function(){return 4}}),void 0!==b.response&&Object.defineProperty(c,"response",{get:function(){return b.response}}),Object.defineProperty(c,"responseText",{get:function(){return b.responseText}}),c.__fileApiXHR=b,c.onreadystatechange()},progress:function(a){a.target=c,c.__progress(a),c.__total=a.total},headers:c.__requestHeaders};e.data={},e.files={};for(var f=0;f',c=c.firstChild;var d=b.parentNode;d.insertBefore(c,b),d.removeChild(b),c.appendChild(b),b.__isWrapped=!0}},c=function(a){return function(b){var c=FileAPI.getFiles(b);b.target||(b.target={}),b.target.files=c,b.target.files.item=function(a){return b.target.files[a]||null},a(b)}},d=function(a,b){return("change"===b.toLowerCase()||"onchange"===b.toLowerCase())&&"file"==a.getAttribute("type")};HTMLInputElement.prototype.addEventListener&&(HTMLInputElement.prototype.addEventListener=function(a){return function(e,f,g,h){d(this,e)?(b(this),a.apply(this,[e,c(f),g,h])):a.apply(this,[e,f,g,h])}}(HTMLInputElement.prototype.addEventListener)),HTMLInputElement.prototype.attachEvent&&(HTMLInputElement.prototype.attachEvent=function(a){return function(e,f){d(this,e)?(b(this),a.apply(this,[e,c(f)])):a.apply(this,[e,f])}}(HTMLInputElement.prototype.attachEvent)),window.FormData=FormData=function(){return{append:function(a,b,c){this.data.push({key:a,val:b,name:c})},data:[],__isShim:!0}},function(){if(window.FileAPI||(window.FileAPI={}),!FileAPI.upload){var b,c,d,e,f,g=document.createElement("script"),h=document.getElementsByTagName("script");if(window.FileAPI.jsUrl)b=window.FileAPI.jsUrl;else if(window.FileAPI.jsPath)c=window.FileAPI.jsPath;else for(d=0;d-1){c=f.substring(0,e);break}null==FileAPI.staticPath&&(FileAPI.staticPath=c),g.setAttribute("src",b||c+"FileAPI.min.js"),document.getElementsByTagName("head")[0].appendChild(g),FileAPI.hasFlash=a()}}()}window.FileReader||(window.FileReader=function(){function a(a,c){var d={type:a,target:b,loaded:c.loaded,total:c.total,error:c.error};return null!=c.result&&(d.target.result=c.result),d}var b=this,c=!1;this.listeners={},this.addEventListener=function(a,c){b.listeners[a]=b.listeners[a]||[],b.listeners[a].push(c)},this.removeEventListener=function(a,c){b.listeners[a]&&b.listeners[a].splice(b.listeners[a].indexOf(c),1)},this.dispatchEvent=function(a){var c=b.listeners[a.type];if(c)for(var d=0;d',c=c.firstChild;var d=b.parentNode;d.insertBefore(c,b),d.removeChild(b),c.appendChild(b),b.__isWrapped=!0}},c=function(a){return function(b){var c=FileAPI.getFiles(b);b.target||(b.target={}),b.target.files=c,b.target.files.item=function(a){return b.target.files[a]||null},a(b)}},d=function(a,b){return("change"===b.toLowerCase()||"onchange"===b.toLowerCase())&&"file"==a.getAttribute("type")};HTMLInputElement.prototype.addEventListener&&(HTMLInputElement.prototype.addEventListener=function(a){return function(e,f,g,h){d(this,e)?(b(this),a.apply(this,[e,c(f),g,h])):a.apply(this,[e,f,g,h])}}(HTMLInputElement.prototype.addEventListener)),HTMLInputElement.prototype.attachEvent&&(HTMLInputElement.prototype.attachEvent=function(a){return function(e,f){d(this,e)?(b(this),a.apply(this,[e,c(f)])):a.apply(this,[e,f])}}(HTMLInputElement.prototype.attachEvent)),window.FormData=FormData=function(){return{append:function(a,b,c){this.data.push({key:a,val:b,name:c})},data:[],__isShim:!0}},function(){if(window.FileAPI||(window.FileAPI={}),!FileAPI.upload){var b,c,d,e,f,g=document.createElement("script"),h=document.getElementsByTagName("script");if(window.FileAPI.jsUrl)b=window.FileAPI.jsUrl;else if(window.FileAPI.jsPath)c=window.FileAPI.jsPath;else for(d=0;d-1){c=f.substring(0,e);break}null==FileAPI.staticPath&&(FileAPI.staticPath=c),g.setAttribute("src",b||c+"FileAPI.min.js"),document.getElementsByTagName("head")[0].appendChild(g),FileAPI.hasFlash=a()}}()}window.FileReader||(window.FileReader=function(){function a(a,c){var d={type:a,target:b,loaded:c.loaded,total:c.total,error:c.error};return null!=c.result&&(d.target.result=c.result),d}var b=this,c=!1;this.listeners={},this.addEventListener=function(a,c){b.listeners[a]=b.listeners[a]||[],b.listeners[a].push(c)},this.removeEventListener=function(a,c){b.listeners[a]&&b.listeners[a].splice(b.listeners[a].indexOf(c),1)},this.dispatchEvent=function(a){var c=b.listeners[a.type];if(c)for(var d=0;d - * @version 1.2.9 + * @version 1.2.10 */ (function() { var angularFileUpload = angular.module('angularFileUpload', []); -angularFileUpload.service('$upload', ['$http', '$rootScope', '$timeout', function($http, $rootScope, $timeout) { +angularFileUpload.service('$upload', ['$http', '$timeout', function($http, $timeout) { function sendHttp(config) { config.method = config.method || 'POST'; config.headers = config.headers || {}; - config.transformRequest = config.transformRequest || function(data) { - if (window.ArrayBuffer && data instanceof ArrayBuffer) { + config.transformRequest = config.transformRequest || function(data, headersGetter) { + if (window.ArrayBuffer && data instanceof window.ArrayBuffer) { return data; } - return $http.defaults.transformRequest[0](data); + return $http.defaults.transformRequest[0](data, headersGetter); }; - + if (window.XMLHttpRequest.__isShim) { config.headers['__setXHR_'] = function() { return function(xhr) { config.__XHR = xhr; + config.xhrFn && config.xhrFn(xhr); xhr.upload.addEventListener('progress', function(e) { if (config.progress) { $timeout(function() { @@ -40,13 +41,13 @@ angularFileUpload.service('$upload', ['$http', '$rootScope', '$timeout', functio } }; } - + var promise = $http(config); - + promise.progress = function(fn) { config.progress = fn; return promise; - }; + }; promise.abort = function() { if (config.__XHR) { $timeout(function() { @@ -54,67 +55,84 @@ angularFileUpload.service('$upload', ['$http', '$rootScope', '$timeout', functio }); } return promise; - }; + }; + promise.xhr = function(fn) { + config.xhrFn = fn; + return promise; + }; promise.then = (function(promise, origThen) { return function(s, e, p) { config.progress = p || config.progress; var result = origThen.apply(promise, [s, e, p]); result.abort = promise.abort; result.progress = promise.progress; + result.xhr = promise.xhr; return result; }; })(promise, promise.then); return promise; - }; + } + this.upload = function(config) { config.headers = config.headers || {}; config.headers['Content-Type'] = undefined; config.transformRequest = config.transformRequest || $http.defaults.transformRequest; var formData = new FormData(); if (config.data) { - for (var key in config.data) { - var val = config.data[key]; - if (!config.formDataAppender) { - if (typeof config.transformRequest == 'function') { - val = config.transformRequest(val); - } else { - for (var i = 0; i < config.transformRequest.length; i++) { - var fn = config.transformRequest[i]; - if (typeof fn == 'function') { - val = fn(val); + if (config.formDataAppender) { + for (var key in config.data) { + var val = config.data[key]; + config.formDataAppender(formData, key, val); + } + config.transformRequest = angular.identity; + } else { + var origTransformRequest = config.transformRequest; + var origData = config.data; + config.transformRequest = function(formData, headerGetter) { + for (var key in origData) { + var val = origData[key]; + if (typeof origTransformRequest == 'function') { + val = origTransformRequest(val, headerGetter); + } else { + for (var i = 0; i < origTransformRequest.length; i++) { + var transformFn = origTransformRequest[i]; + if (typeof transformFn == 'function') { + val = transformFn(val, headerGetter); + } } } + formData.append(key, val); } - formData.append(key, val); - } else { - config.formDataAppender(formData, key, val); - } + return formData; + }; } } - config.transformRequest = angular.identity; - - var fileFormName = config.fileFormDataName || 'file'; - - if (Object.prototype.toString.call(config.file) === '[object Array]') { - var isFileFormNameString = Object.prototype.toString.call(fileFormName) === '[object String]'; - for (var i = 0; i < config.file.length; i++) { - formData.append(isFileFormNameString ? fileFormName + i : fileFormName[i], config.file[i], config.file[i].name); + + if (config.file != null) { + var fileFormName = config.fileFormDataName || 'file'; + + if (Object.prototype.toString.call(config.file) === '[object Array]') { + var isFileFormNameString = Object.prototype.toString.call(fileFormName) === '[object String]'; + for (var i = 0; i < config.file.length; i++) { + formData.append(isFileFormNameString ? fileFormName + i : fileFormName[i], config.file[i], config.file[i].name); + } + } else { + formData.append(fileFormName, config.file, config.file.name); } - } else { - formData.append(fileFormName, config.file, config.file.name); } - + config.data = formData; - + return sendHttp(config); }; + this.http = function(config) { return sendHttp(config); } }]); -angularFileUpload.directive('ngFileSelect', [ '$parse', '$http', '$timeout', function($parse, $http, $timeout) { +angularFileUpload.directive('ngFileSelect', [ '$parse', '$timeout', function($parse, $timeout) { return function(scope, elem, attr) { var fn = $parse(attr['ngFileSelect']); elem.bind('change', function(evt) { @@ -138,7 +156,7 @@ angularFileUpload.directive('ngFileSelect', [ '$parse', '$http', '$timeout', fun }; } ]); -angularFileUpload.directive('ngFileDropAvailable', [ '$parse', '$http', '$timeout', function($parse, $http, $timeout) { +angularFileUpload.directive('ngFileDropAvailable', [ '$parse', '$timeout', function($parse, $timeout) { return function(scope, elem, attr) { if ('draggable' in document.createElement('span')) { var fn = $parse(attr['ngFileDropAvailable']); @@ -149,7 +167,7 @@ angularFileUpload.directive('ngFileDropAvailable', [ '$parse', '$http', '$timeou }; } ]); -angularFileUpload.directive('ngFileDrop', [ '$parse', '$http', '$timeout', function($parse, $http, $timeout) { +angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', function($parse, $timeout) { return function(scope, elem, attr) { if ('draggable' in document.createElement('span')) { var cancel = null; diff --git a/dist/angular-file-upload.min.js b/dist/angular-file-upload.min.js index 4fa3cc7a..a9891db1 100644 --- a/dist/angular-file-upload.min.js +++ b/dist/angular-file-upload.min.js @@ -1,2 +1,2 @@ -/*! 1.2.9 */ -!function(){var a=angular.module("angularFileUpload",[]);a.service("$upload",["$http","$rootScope","$timeout",function(a,b,c){function d(b){b.method=b.method||"POST",b.headers=b.headers||{},b.transformRequest=b.transformRequest||function(b){return window.ArrayBuffer&&b instanceof ArrayBuffer?b:a.defaults.transformRequest[0](b)},window.XMLHttpRequest.__isShim&&(b.headers.__setXHR_=function(){return function(a){b.__XHR=a,a.upload.addEventListener("progress",function(a){b.progress&&c(function(){b.progress&&b.progress(a)})},!1),a.upload.addEventListener("load",function(a){a.lengthComputable&&c(function(){b.progress&&b.progress(a)})},!1)}});var d=a(b);return d.progress=function(a){return b.progress=a,d},d.abort=function(){return b.__XHR&&c(function(){b.__XHR.abort()}),d},d.then=function(a,c){return function(d,e,f){b.progress=f||b.progress;var g=c.apply(a,[d,e,f]);return g.abort=a.abort,g.progress=a.progress,g}}(d,d.then),d}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;if(b.data)for(var e in b.data){var f=b.data[e];if(b.formDataAppender)b.formDataAppender(c,e,f);else{if("function"==typeof b.transformRequest)f=b.transformRequest(f);else for(var g=0;g angular-file-upload Angular file upload - 1.2.9 + 1.2.10 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 1288e81a..f5de32e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-file-upload", - "version": "1.2.9", + "version": "1.2.10", "devDependencies": { "grunt": "~0.4.1", "grunt-contrib-uglify": "~0.2.7",