Skip to content

Commit c55a1e2

Browse files
committed
* _convertFile; + isPhantomJS
1 parent 9902531 commit c55a1e2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/FileAPI.Form.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*global window, FileAPI */
1+
/*global window, navigator, FileAPI */
22

33
(function (api, window){
44
"use strict";
@@ -8,6 +8,7 @@
88
, FormData = window.FormData
99
, Form = function (){ this.items = []; }
1010
, encodeURIComponent = window.encodeURIComponent
11+
, isPhantomJS = /phantomjs/i.test(navigator.userAgent)// @todo: fixed it
1112
;
1213

1314

@@ -38,7 +39,7 @@
3839
api.log('FileAPI.Form.toHtmlData');
3940
this.toHtmlData(fn);
4041
}
41-
else if( this.multipart || !FormData ){
42+
else if( isPhantomJS || this.multipart || !FormData ){
4243
api.log('FileAPI.Form.toMultipartData');
4344
this.toMultipartData(fn);
4445
}
@@ -94,7 +95,7 @@
9495
if( file.blob.toBlob ){
9596
// canvas
9697
queue.inc();
97-
_converFile(file, function (file, blob){
98+
_convertFile(file, function (file, blob){
9899
data.name = file.name;
99100
data.file = blob;
100101
data.size = blob.length;
@@ -127,7 +128,7 @@
127128
this._to(new FormData, fn, function (file, data, queue){
128129
if( file.blob && file.blob.toBlob ){
129130
queue.inc();
130-
_converFile(file, function (file, blob){
131+
_convertFile(file, function (file, blob){
131132
data.append(file.name, blob, file.file);
132133
queue.next();
133134
});
@@ -149,7 +150,7 @@
149150
toMultipartData: function (fn){
150151
this._to([], fn, function (file, data, queue, boundary){
151152
queue.inc();
152-
_converFile(file, function (file, blob){
153+
_convertFile(file, function (file, blob){
153154
data.push(
154155
'--_' + boundary + ('\r\nContent-Disposition: form-data; name="'+ file.name +'"'+ (file.file ? '; filename="'+ encodeURIComponent(file.file) +'"' : '')
155156
+ (file.file ? '\r\nContent-Type: '+ (file.type || 'application/octet-stream') : '')
@@ -158,13 +159,13 @@
158159
+ '\r\n')
159160
);
160161
queue.next();
161-
});
162+
}, true);
162163
}, api.expando);
163164
}
164165
};
165166

166167

167-
function _converFile(file, fn){
168+
function _convertFile(file, fn, useBinaryString){
168169
var blob = file.blob, filename = file.file;
169170

170171
if( filename ){
@@ -193,7 +194,7 @@
193194
file.file = filename;
194195
file.type = type;
195196

196-
if( blob.toBlob ){
197+
if( !useBinaryString && blob.toBlob ){
197198
blob.toBlob(function (blob){
198199
fn(file, blob);
199200
}, type, quality);

0 commit comments

Comments
 (0)