Skip to content

Commit 3e1b404

Browse files
committed
* Multipart
1 parent 60992ab commit 3e1b404

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lib/FileAPI.Form.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
api.log('FileAPI.Form.toHtmlData');
3939
this.toHtmlData(fn);
4040
}
41-
else if( this.multipart ){
41+
else if( this.multipart || !FormData ){
4242
api.log('FileAPI.Form.toMultipartData');
4343
this.toMultipartData(fn);
4444
}
@@ -148,6 +148,7 @@
148148

149149
toMultipartData: function (fn){
150150
this._to([], fn, function (file, data, queue, boundary){
151+
queue.inc();
151152
_converFile(file, function (file, blob){
152153
data.push(
153154
'--_' + boundary + ('\r\nContent-Disposition: form-data; name="'+ file.name +'"'+ (file.file ? '; filename="'+ encodeURIComponent(file.file) +'"' : '')
@@ -156,6 +157,7 @@
156157
+ '\r\n'+ (file.file ? blob : encodeURIComponent(blob))
157158
+ '\r\n')
158159
);
160+
queue.next();
159161
});
160162
}, api.expando);
161163
}
@@ -166,6 +168,15 @@
166168
var blob = file.blob, filename = file.file;
167169

168170
if( filename ){
171+
if( !blob.toDataURL ){
172+
api.readAsBinaryString(blob, function (evt){
173+
if( evt.type == 'load' ){
174+
fn(file, evt.result);
175+
}
176+
});
177+
return;
178+
}
179+
169180
var
170181
mime = { 'image/jpeg': '.jpe?g', 'image/png': '.png' }
171182
, type = mime[file.type] ? file.type : 'image/png'
@@ -186,11 +197,12 @@
186197
}, type, quality);
187198
}
188199
else {
189-
blob = api.toBinaryString(blob.toDataURL(type, quality));
200+
fn(file, api.toBinaryString(blob.toDataURL(type, quality)));
190201
}
191202
}
192-
193-
returnblob;
203+
else {
204+
fn(file, blob);
205+
}
194206
}
195207

196208

0 commit comments

Comments
 (0)