Skip to content

Commit 5bad27c

Browse files
committed
* fixed uploading FileAPI.Image
1 parent 16b3d7a commit 5bad27c

File tree

8 files changed

+49
-22
lines changed

8 files changed

+49
-22
lines changed

dist/FileAPI.html5.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@
10511051
});
10521052

10531053
// Set upload status props
1054-
proxyXHR.total = _total = (_total || 1);
1054+
proxyXHR.total = _total;
10551055
proxyXHR.loaded = 0;
10561056
proxyXHR.filesLeft = dataArray.length;
10571057

@@ -1086,7 +1086,6 @@
10861086

10871087
_this._getFormData(_fileOptions, data, function (form){
10881088
if( !_loaded ){
1089-
data.size = data.size || 1;
10901089
// emit "upload" event
10911090
options.upload(proxyXHR, options);
10921091
}
@@ -1100,6 +1099,9 @@
11001099

11011100
progress: _file ? function (evt){
11021101
if( !_fileLoaded ){
1102+
// For ignore the double calls.
1103+
_fileLoaded = (evt.loaded === evt.total);
1104+
11031105
// emit "fileprogress" event
11041106
options.fileprogress({
11051107
type: 'progress'
@@ -1800,6 +1802,8 @@
18001802
}
18011803

18021804
this.file = file;
1805+
this.size = file.size || 100;
1806+
18031807
this.matrix = {
18041808
sx: 0,
18051809
sy: 0,
@@ -2075,11 +2079,13 @@
20752079
else {
20762080
fn('not_support_transform');
20772081
}
2082+
2083+
return this;
20782084
},
20792085

20802086

20812087
toData: function (fn){
2082-
this.get(fn);
2088+
return this.get(fn);
20832089
}
20842090

20852091
};

dist/FileAPI.html5.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/FileAPI.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@
10511051
});
10521052

10531053
// Set upload status props
1054-
proxyXHR.total = _total = (_total || 1);
1054+
proxyXHR.total = _total;
10551055
proxyXHR.loaded = 0;
10561056
proxyXHR.filesLeft = dataArray.length;
10571057

@@ -1086,7 +1086,6 @@
10861086

10871087
_this._getFormData(_fileOptions, data, function (form){
10881088
if( !_loaded ){
1089-
data.size = data.size || 1;
10901089
// emit "upload" event
10911090
options.upload(proxyXHR, options);
10921091
}
@@ -1100,6 +1099,9 @@
11001099

11011100
progress: _file ? function (evt){
11021101
if( !_fileLoaded ){
1102+
// For ignore the double calls.
1103+
_fileLoaded = (evt.loaded === evt.total);
1104+
11031105
// emit "fileprogress" event
11041106
options.fileprogress({
11051107
type: 'progress'
@@ -1800,6 +1802,8 @@
18001802
}
18011803

18021804
this.file = file;
1805+
this.size = file.size || 100;
1806+
18031807
this.matrix = {
18041808
sx: 0,
18051809
sy: 0,
@@ -2075,11 +2079,13 @@
20752079
else {
20762080
fn('not_support_transform');
20772081
}
2082+
2083+
return this;
20782084
},
20792085

20802086

20812087
toData: function (fn){
2082-
this.get(fn);
2088+
return this.get(fn);
20832089
}
20842090

20852091
};
@@ -3649,7 +3655,7 @@
36493655
api.Image && _inherit(api.Image.prototype, {
36503656
get: function (fn, scaleMode){
36513657
this.set({ scaleMode: scaleMode || 'noScale' }); // noScale, exactFit
3652-
this.parent(fn);
3658+
return this.parent(fn);
36533659
},
36543660

36553661
_load: function (file, fn){

dist/FileAPI.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/FileAPI.Flash.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@
403403
api.Image && _inherit(api.Image.prototype, {
404404
get: function (fn, scaleMode){
405405
this.set({ scaleMode: scaleMode || 'noScale' }); // noScale, exactFit
406-
this.parent(fn);
406+
return this.parent(fn);
407407
},
408408

409409
_load: function (file, fn){

lib/FileAPI.Image.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
}
3333

3434
this.file = file;
35+
this.size = file.size || 100;
36+
3537
this.matrix = {
3638
sx: 0,
3739
sy: 0,
@@ -307,11 +309,13 @@
307309
else {
308310
fn('not_support_transform');
309311
}
312+
313+
return this;
310314
},
311315

312316

313317
toData: function (fn){
314-
this.get(fn);
318+
return this.get(fn);
315319
}
316320

317321
};

lib/FileAPI.core.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@
957957
});
958958

959959
// Set upload status props
960-
proxyXHR.total = _total = (_total || 1);
960+
proxyXHR.total = _total;
961961
proxyXHR.loaded = 0;
962962
proxyXHR.filesLeft = dataArray.length;
963963

@@ -992,7 +992,6 @@
992992

993993
_this._getFormData(_fileOptions, data, function (form){
994994
if( !_loaded ){
995-
data.size = data.size || 1;
996995
// emit "upload" event
997996
options.upload(proxyXHR, options);
998997
}
@@ -1006,6 +1005,9 @@
10061005

10071006
progress: _file ? function (evt){
10081007
if( !_fileLoaded ){
1008+
// For ignore the double calls.
1009+
_fileLoaded = (evt.loaded === evt.total);
1010+
10091011
// emit "fileprogress" event
10101012
options.fileprogress({
10111013
type: 'progress'

tests/tests.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,19 @@ module('FileAPI');
329329

330330

331331
test('upload file', function (){
332-
var _progressFail = false;
332+
var _progressFail = false, _progress = 0;
333333
stop();
334334

335335
FileAPI.upload({
336336
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
337337
files: { text: FileAPI.getFiles(uploadForm['hello.txt']) },
338338
progress: function (evt){
339339
_progressFail = _progressFail || _checkProgressEvent(evt);
340+
if( !_progressFail && (_progress >= evt.loaded) ){
341+
_progressFail = true;
342+
ok(false, 'progress evt.loaded: '+_progress+' -> '+evt.loaded);
343+
}
344+
_progress = evt.loaded;
340345
},
341346
complete: function (err, res){
342347
start();
@@ -372,18 +377,17 @@ module('FileAPI');
372377
_files[file.name] = file;
373378
},
374379
progress: function (evt){
375-
if( _progress > evt.loaded ){
380+
_progressFail = _progressFail || _checkProgressEvent(evt);
381+
if( !_progressFail && (_progress >= evt.loaded) ){
376382
_progressFail = true;
383+
ok(false, 'progress evt.loaded: '+_progress+' -> '+evt.loaded);
377384
}
378-
379385
_progress = evt.loaded;
380-
_progressFail = _progressFail || _checkProgressEvent(evt);
381386
},
382387
complete: function (err, xhr){
383388
start();
384389

385390
equal(_start, _complete, 'uploaded');
386-
equal(_progressFail, false, 'progress');
387391

388392
checkFile(_files['1px.gif'], '1px.gif', 'image/gif', 34);
389393
checkFile(_files['dino.png'], 'dino.png', 'image/png', 461003);
@@ -398,21 +402,26 @@ module('FileAPI');
398402
FileAPI.html5 && test('upload FileAPI.Image', function (){
399403
var file = FileAPI.getFiles(uploadForm['dino.png'])[0];
400404
var image = FileAPI.Image(file).rotate(90).preview(100);
401-
var _progressFail = false, _progress = false;
405+
var _progressFail = false, _progress = 0;
402406

403407
stop();
404408
FileAPI.upload({
405409
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
406410
headers: { 'x-foo': 'bar' },
407411
files: { image: image },
408412
progress: function (evt){
409-
_progress = true;
410413
_progressFail = _progressFail || _checkProgressEvent(evt);
414+
415+
if( !_progressFail && (_progress >= evt.loaded) ){
416+
_progressFail = true;
417+
ok(false, 'progress evt.loaded: '+_progress+' -> '+evt.loaded);
418+
}
419+
_progress = evt.loaded;
411420
},
412421
complete: function (err, res){
413422
var res = FileAPI.parseJSON(res.responseText);
414423

415-
ok(_progress, 'progress event');
424+
ok(_progress > 0, 'progress event');
416425
equal(res.data.HEADERS['X-Foo'], 'bar', 'X-Foo');
417426

418427
imageEqual(res.images.image.dataURL, 'files/samples/'+browser+'-dino-90deg-100x100.png?1', 'dino 90deg 100x100', function (){

0 commit comments

Comments
 (0)