Skip to content

Commit c6907ba

Browse files
committed
fix mailru/FileAPI#311 uncaught exception in IE10-11 when FormData#append(gt4GB)
1 parent 4aa414b commit c6907ba

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

lib/FileAPI.Form.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,38 @@
129129
if( file.blob && file.blob.toBlob ){
130130
queue.inc();
131131
_convertFile(file, function (file, blob){
132-
data.append(file.name, blob, file.file);
132+
try{
133+
// FromData#append throws exception in IE10-11,
134+
// when a file size is larger than 4GB
135+
data.append(file.name, blob, file.file);
136+
}catch( err1 ){
137+
data._error = err1;
138+
}
139+
133140
queue.next();
134141
});
135142
}
136-
else if( file.file ){
137-
data.append(file.name, file.blob, file.file);
138-
}
139-
else {
140-
data.append(file.name, file.blob);
143+
else{
144+
try{
145+
if( file.file ){
146+
data.append(file.name, file.blob, file.file);
147+
}
148+
else{
149+
data.append(file.name, file.blob);
150+
}
151+
}
152+
catch( err2 ){
153+
data._error = err2;
154+
}
141155
}
142156

143157
if( file.file ){
144-
data.append('_'+file.name, file.file);
158+
try{
159+
data.append('_'+file.name, file.file);
160+
}
161+
catch( err3 ){
162+
data._error = err3;
163+
}
145164
}
146165
});
147166
},

lib/FileAPI.XHR.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,16 @@
7171
var _this = this, options = this.options;
7272

7373
FormData.toData(function (data){
74-
// Start uploading
75-
options.upload(options, _this);
76-
_this._send.call(_this, options, data);
74+
75+
if( data._error ){
76+
_this.end(0, data._error.message);
77+
}
78+
else{
79+
// Start uploading
80+
options.upload(options, _this);
81+
_this._send.call(_this, options, data);
82+
}
83+
7784
}, options);
7885
},
7986

0 commit comments

Comments
 (0)