11
11
document . write ( '<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/' + ( angularVersion || '1.2.0' ) + '/angular.js"><\/script>' ) ;
12
12
</ script >
13
13
< script src ="js/angular-file-upload.js "> </ script >
14
+ < script src ="js/upload.js "> </ script >
14
15
<!-- <script src="http://cdn.jsdelivr.net/angular.file-upload/1.0.0/angular-file-upload.min.js"></script> -->
15
16
</ head >
16
17
@@ -23,9 +24,14 @@ <h1>Angular file upload Demo</h1>
23
24
< h3 >
24
25
Visit < a href ="https://github.com/danialfarid/angular-file-upload "> angular-file-upload</ a > on github
25
26
</ h3 >
26
-
27
- < div >
28
- Model object to be sent to the server with the file: < input type ="text " ng-model ="myModel "> < br />
27
+ < div class ="upload-div ">
28
+ < label > < input type ="radio " name ="howToSend " ng-model ="howToSend " value ="1 " ng-init ="howToSend = 1 "> model object to be sent as data to the server with the file: < input type ="text " ng-model ="myModel "> </ label > < br />
29
+ < label > < input type ="radio " name ="howToSend " ng-model ="howToSend " value ="2 " ng-disabled ="!dropSupported "> or send the file binary as data with a POST/PUT request instead of multipart/form-data upload. </ label >
30
+ < div class ="sub "> For < a href ="https://github.com/danialfarid/angular-file-upload/issues/88 "> CouchDB</ a > ,
31
+ < a href ="https://github.com/danialfarid/angular-file-upload/issues/87 "> imgur</ a > , etc.
32
+ Only HTML5 FileReader browsers, cross browser support will be added around Feb 2014 when FileAPI FileReader support is available.
33
+ </ div > < br /> < br />
34
+ http method: < input type ="radio " ng-model ="httpMethod " ng-init ="httpMethod = 'POST' " value ="POST "/> post < input type ="radio " ng-model ="httpMethod " value ='PUT '/> put< br />
29
35
choose a single file: < input type ="file " ng-file-select ="onFileSelect($files) ">
30
36
< br />
31
37
or multiple files: < input type ="file " ng-file-select ="onFileSelect($files) " multiple >
42
48
< br />
43
49
< div ng-show ="selectedFiles != null ">
44
50
< div class ="sel-file " ng-repeat ="f in selectedFiles ">
45
- < img ng-show ="dataUrls[$index] " src ="{{dataUrls[$index]}} ">
51
+ < img ng-show ="dataUrls[$index] " ng- src ="{{dataUrls[$index]}} ">
46
52
< button class ="button " ng-click ="start($index) " ng-show ="progress[$index] < 0 "> Start</ button >
47
53
< span class ="progress " ng-show ="progress[$index] >= 0 ">
48
54
< div style ="width:{{progress[$index]}}% "> {{progress[$index]}}%</ div >
67
73
</ ul >
68
74
</ div >
69
75
</ div >
70
-
71
- < script type ="text/javascript ">
72
- angular . module ( 'fileUpload' , [ 'angularFileUpload' ] ) ;
73
-
74
- var MyCtrl = [ '$scope' , '$http' , '$timeout' , '$upload' , function ( $scope , $http , $timeout , $upload ) {
75
- $scope . uploadRightAway = true ;
76
- $scope . changeAngularVersion = function ( ) {
77
- window . location . hash = $scope . angularVersion ;
78
- window . location . reload ( true ) ;
79
- }
80
- $scope . hasUploader = function ( index ) {
81
- return $scope . upload [ index ] != null ;
82
- } ;
83
- $scope . abort = function ( index ) {
84
- $scope . upload [ index ] . abort ( ) ;
85
- $scope . upload [ index ] = null ;
86
- } ;
87
- $scope . angularVersion = window . location . hash . length > 1 ? window . location . hash . substring ( 1 ) : '1.2.0' ;
88
- $scope . onFileSelect = function ( $files ) {
89
- $scope . selectedFiles = [ ] ;
90
- $scope . progress = [ ] ;
91
- if ( $scope . upload && $scope . upload . length > 0 ) {
92
- for ( var i = 0 ; i < $scope . upload . length ; i ++ ) {
93
- if ( $scope . upload [ i ] != null ) {
94
- $scope . upload [ i ] . abort ( ) ;
95
- }
96
- }
97
- }
98
- $scope . upload = [ ] ;
99
- $scope . uploadResult = [ ] ;
100
- $scope . selectedFiles = $files ;
101
- $scope . dataUrls = [ ] ;
102
- for ( var i = 0 ; i < $files . length ; i ++ ) {
103
- var $file = $files [ i ] ;
104
- if ( window . FileReader && $file . type . indexOf ( 'image' ) > - 1 ) {
105
- var fileReader = new FileReader ( ) ;
106
- fileReader . readAsDataURL ( $files [ i ] ) ;
107
- function setPreview ( fileReader , index ) {
108
- fileReader . onload = function ( e ) {
109
- $timeout ( function ( ) {
110
- $scope . dataUrls [ index ] = e . target . result ;
111
- } ) ;
112
- }
113
- }
114
- setPreview ( fileReader , i ) ;
115
- }
116
- $scope . progress [ i ] = - 1 ;
117
- if ( $scope . uploadRightAway ) {
118
- $scope . start ( i ) ;
119
- }
120
- }
121
- }
122
-
123
- $scope . start = function ( index ) {
124
- $scope . progress [ index ] = 0 ;
125
- $scope . upload [ index ] = $upload . upload ( {
126
- url : 'upload' ,
127
- headers : { 'myHeaderKey' : 'myHeaderVal' } ,
128
- data : {
129
- myModel : $scope . myModel
130
- } ,
131
- /* formDataAppender: function(fd, key, val) {
132
- if (angular.isArray(val)) {
133
- angular.forEach(val, function(v) {
134
- fd.append(key, v);
135
- });
136
- } else {
137
- fd.append(key, val);
138
- }
139
- }, */
140
- file : $scope . selectedFiles [ index ] ,
141
- fileFormDataName : 'myFile'
142
- } ) . then ( function ( response ) {
143
- $scope . uploadResult . push ( response . data . result ) ;
144
- } , null , function ( evt ) {
145
- $scope . progress [ index ] = parseInt ( 100.0 * evt . loaded / evt . total ) ;
146
- } ) ;
147
- }
148
- } ] ;
149
- </ script >
150
76
</ body >
151
77
</ html >
0 commit comments