File tree 2 files changed +36
-8
lines changed 2 files changed +36
-8
lines changed Original file line number Diff line number Diff line change 27
27
} ,
28
28
29
29
toData : function ( fn , options ) {
30
+ // allow chunked transfer if we have only one file to send
31
+ // flag is used below and in XHR._send
32
+ options . _chunked = api . support . chunked && options . chunkSize > 0 && api . filter ( this . items , function ( item ) { return item . file ; } ) . length == 1 ;
33
+
30
34
if ( ! api . support . html5 ) {
31
35
api . log ( 'FileAPI.Form.toHtmlData' ) ;
32
36
this . toHtmlData ( fn ) ;
35
39
api . log ( 'FileAPI.Form.toMultipartData' ) ;
36
40
this . toMultipartData ( fn ) ;
37
41
}
38
- else if ( api . support . chunked && options . chunkSize > 0 ) {
39
- api . log ( 'FileAPI.Form.toMultipartData ' ) ;
42
+ else if ( options . _chunked ) {
43
+ api . log ( 'FileAPI.Form.toPlainData ' ) ;
40
44
this . toPlainData ( fn ) ;
41
45
}
42
46
else {
83
87
if ( file . file ) {
84
88
data . type = file . file ;
85
89
}
86
- data . name = file . blob . name ;
87
- data . file = file . blob ;
88
- data . size = file . blob . size ;
90
+ if ( file . blob . toBlob ) {
91
+ // canvas
92
+ queue . inc ( ) ;
93
+ file . blob . toBlob ( function ( blob ) {
94
+ data . name = file . name ;
95
+ data . file = blob ;
96
+ data . size = blob . length ;
97
+ queue . next ( ) ;
98
+ } , 'image/png' ) ;
99
+ }
100
+ else if ( file . file ) {
101
+ //file
102
+ data . name = file . blob . name ;
103
+ data . file = file . blob ;
104
+ data . size = file . blob . size ;
105
+ }
106
+ else {
107
+ // additional data
108
+ if ( ! data . params ) {
109
+ data . params = [ ] ;
110
+ }
111
+ data . params . push ( encodeURIComponent ( file . name ) + "=" + encodeURIComponent ( file . blob ) ) ;
112
+ }
89
113
data . start = 0 ;
90
114
data . end = 0 ;
91
115
data . retry = 0 ;
Original file line number Diff line number Diff line change 129
129
// html5
130
130
xhr = _this . xhr = api . getXHR ( ) ;
131
131
132
+ if ( data . params ) {
133
+ url += ( url . indexOf ( '?' ) < 0 ? "?" : "&" ) + data . params . join ( "&" ) ;
134
+ }
135
+
132
136
xhr . open ( 'POST' , url , true ) ;
133
137
xhr . withCredential = "true" ;
134
138
141
145
} ) ;
142
146
143
147
144
- if ( api . support . chunked && options . chunkSize > 0 ) {
145
- // resumable upload
148
+ if ( options . _chunked ) {
149
+ // chunked upload
146
150
if ( xhr . upload ) {
147
151
// https://github.com/blueimp/jQuery-File-Upload/wiki/Fixing-Safari-hanging-on-very-high-speed-connections-%281Gbps%29
148
152
xhr . upload . addEventListener ( 'progress' , api . throttle ( function ( /**Event*/ evt ) {
199
203
( slice = 'slice' ) in data . file || ( slice = 'mozSlice' ) in data . file || ( slice = 'webkitSlice' ) in data . file ;
200
204
201
205
xhr . setRequestHeader ( "Content-Range" , "bytes " + data . start + "-" + data . end + "/" + data . size ) ;
202
- xhr . setRequestHeader ( "Content-Disposition" , 'attachment; filename=' + data . name ) ;
206
+ xhr . setRequestHeader ( "Content-Disposition" , 'attachment; filename=' + encodeURIComponent ( data . name ) ) ;
203
207
204
208
slice = data . file [ slice ] ( data . start , data . end + 1 ) ;
205
209
You can’t perform that action at this time.
0 commit comments