Skip to content

Commit 090eb3a

Browse files
committed
+ merge #140
2 parents 14dc3a6 + e91fc1e commit 090eb3a

File tree

7 files changed

+86
-44
lines changed

7 files changed

+86
-44
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,9 +1499,9 @@ Button like link.
14991499
<li>+iOS fix (https://github.com/blueimp/JavaScript-Load-Image)</li>
15001500
<li>[#121](https://github.com/mailru/FileAPI/issues/121): + FileAPI.`postNameConcat:Function(name, idx)`</li>
15011501
<li>[#116](https://github.com/mailru/FileAPI/issues/116): + `cache:false` option for FileAPI.upload</li>
1502+
<li>fix `isArray` for Safari 5</li>
15021503
</ul>
15031504
1504-
15051505
### 1.2.6
15061506
<ul>
15071507
<li>[#91](https://github.com/mailru/FileAPI/issues/91): replace `new Image` to `FileAPI.newImage`</li>

dist/FileAPI.html5.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,7 +2614,6 @@
26142614
xhr = _this.xhr = api.getXHR();
26152615

26162616
if( data.params ){
2617-
// @todo: Узнать что это и зачем, а потом удалить
26182617
url += (url.indexOf('?') < 0 ? "?" : "&") + data.params.join("&");
26192618
}
26202619

@@ -2633,11 +2632,11 @@
26332632
});
26342633

26352634

2636-
if ( options._chunked ) {
2635+
if( options._chunked ){
26372636
// chunked upload
26382637
if( xhr.upload ){
2639-
xhr.upload.addEventListener('progress', function (/**Event*/evt){
2640-
if (!data.retry) {
2638+
xhr.upload.addEventListener('progress', api.throttle(function (/**Event*/evt){
2639+
if( !data.retry ){
26412640
// show progress only for correct chunk uploads
26422641
options.progress({
26432642
type: evt.type
@@ -2646,7 +2645,7 @@
26462645
, totalSize: data.size
26472646
}, _this, options);
26482647
}
2649-
}, false);
2648+
}, 100), false);
26502649
}
26512650

26522651
xhr.onreadystatechange = function (){
@@ -2662,7 +2661,7 @@
26622661
}
26632662
xhr.onreadystatechange = null;
26642663

2665-
if (!xhr.status || xhr.status - 201 > 0) {
2664+
if( !xhr.status || xhr.status - 201 > 0 ){
26662665
api.log("Error: " + xhr.status);
26672666
// some kind of error
26682667
// 0 - connection fail or timeout, if xhr.aborted is true, then it's not recoverable user action
@@ -2681,6 +2680,9 @@
26812680
data.end = lkb;
26822681
} else {
26832682
data.end = data.start - 1;
2683+
if (416 == xhr.status) {
2684+
data.end = data.end - options.chunkSize;
2685+
}
26842686
}
26852687

26862688
setTimeout(function () {
@@ -2712,7 +2714,12 @@
27122714
}, 0);
27132715
}
27142716
}
2717+
27152718
xhr = null;
2719+
2720+
if( slice ){
2721+
slice = null;
2722+
}
27162723
}
27172724
};
27182725

@@ -2722,13 +2729,20 @@
27222729
var slice;
27232730
(slice = 'slice') in data.file || (slice = 'mozSlice') in data.file || (slice = 'webkitSlice') in data.file;
27242731

2725-
xhr.setRequestHeader("Content-Range", "bytes " + data.start + "-" + data.end + "/" + data.size);
2726-
xhr.setRequestHeader("Content-Disposition", 'attachment; filename=' + encodeURIComponent(data.name));
2727-
xhr.setRequestHeader("Content-Type", data.type || "application/octet-stream");
2728-
2729-
slice = data.file[slice](data.start, data.end + 1);
2730-
2731-
xhr.send(slice);
2732+
slice = data.file[slice](data.start, data.end + 1);
2733+
2734+
if( data.size && !slice.size ){
2735+
setTimeout(function (){
2736+
_this.end(-1);
2737+
});
2738+
} else {
2739+
xhr.setRequestHeader("Content-Range", "bytes " + data.start + "-" + data.end + "/" + data.size);
2740+
xhr.setRequestHeader("Content-Disposition", 'attachment; filename=' + encodeURIComponent(data.name));
2741+
xhr.setRequestHeader("Content-Type", data.type || "application/octet-stream");
2742+
2743+
xhr.send(slice);
2744+
}
2745+
27322746
slice = null;
27332747
} else {
27342748
// single piece upload

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: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,7 +2614,6 @@
26142614
xhr = _this.xhr = api.getXHR();
26152615

26162616
if( data.params ){
2617-
// @todo: Узнать что это и зачем, а потом удалить
26182617
url += (url.indexOf('?') < 0 ? "?" : "&") + data.params.join("&");
26192618
}
26202619

@@ -2633,11 +2632,11 @@
26332632
});
26342633

26352634

2636-
if ( options._chunked ) {
2635+
if( options._chunked ){
26372636
// chunked upload
26382637
if( xhr.upload ){
2639-
xhr.upload.addEventListener('progress', function (/**Event*/evt){
2640-
if (!data.retry) {
2638+
xhr.upload.addEventListener('progress', api.throttle(function (/**Event*/evt){
2639+
if( !data.retry ){
26412640
// show progress only for correct chunk uploads
26422641
options.progress({
26432642
type: evt.type
@@ -2646,7 +2645,7 @@
26462645
, totalSize: data.size
26472646
}, _this, options);
26482647
}
2649-
}, false);
2648+
}, 100), false);
26502649
}
26512650

26522651
xhr.onreadystatechange = function (){
@@ -2662,7 +2661,7 @@
26622661
}
26632662
xhr.onreadystatechange = null;
26642663

2665-
if (!xhr.status || xhr.status - 201 > 0) {
2664+
if( !xhr.status || xhr.status - 201 > 0 ){
26662665
api.log("Error: " + xhr.status);
26672666
// some kind of error
26682667
// 0 - connection fail or timeout, if xhr.aborted is true, then it's not recoverable user action
@@ -2681,6 +2680,9 @@
26812680
data.end = lkb;
26822681
} else {
26832682
data.end = data.start - 1;
2683+
if (416 == xhr.status) {
2684+
data.end = data.end - options.chunkSize;
2685+
}
26842686
}
26852687

26862688
setTimeout(function () {
@@ -2712,7 +2714,12 @@
27122714
}, 0);
27132715
}
27142716
}
2717+
27152718
xhr = null;
2719+
2720+
if( slice ){
2721+
slice = null;
2722+
}
27162723
}
27172724
};
27182725

@@ -2722,13 +2729,20 @@
27222729
var slice;
27232730
(slice = 'slice') in data.file || (slice = 'mozSlice') in data.file || (slice = 'webkitSlice') in data.file;
27242731

2725-
xhr.setRequestHeader("Content-Range", "bytes " + data.start + "-" + data.end + "/" + data.size);
2726-
xhr.setRequestHeader("Content-Disposition", 'attachment; filename=' + encodeURIComponent(data.name));
2727-
xhr.setRequestHeader("Content-Type", data.type || "application/octet-stream");
2728-
2729-
slice = data.file[slice](data.start, data.end + 1);
2730-
2731-
xhr.send(slice);
2732+
slice = data.file[slice](data.start, data.end + 1);
2733+
2734+
if( data.size && !slice.size ){
2735+
setTimeout(function (){
2736+
_this.end(-1);
2737+
});
2738+
} else {
2739+
xhr.setRequestHeader("Content-Range", "bytes " + data.start + "-" + data.end + "/" + data.size);
2740+
xhr.setRequestHeader("Content-Disposition", 'attachment; filename=' + encodeURIComponent(data.name));
2741+
xhr.setRequestHeader("Content-Type", data.type || "application/octet-stream");
2742+
2743+
xhr.send(slice);
2744+
}
2745+
27322746
slice = null;
27332747
} else {
27342748
// single piece upload

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.

dist/jquery.fileapi.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.

lib/FileAPI.XHR.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@
145145
xhr = _this.xhr = api.getXHR();
146146

147147
if( data.params ){
148-
// @todo: Узнать что это и зачем, а потом удалить
149148
url += (url.indexOf('?') < 0 ? "?" : "&") + data.params.join("&");
150149
}
151150

@@ -164,11 +163,11 @@
164163
});
165164

166165

167-
if ( options._chunked ) {
166+
if( options._chunked ){
168167
// chunked upload
169168
if( xhr.upload ){
170-
xhr.upload.addEventListener('progress', function (/**Event*/evt){
171-
if (!data.retry) {
169+
xhr.upload.addEventListener('progress', api.throttle(function (/**Event*/evt){
170+
if( !data.retry ){
172171
// show progress only for correct chunk uploads
173172
options.progress({
174173
type: evt.type
@@ -177,7 +176,7 @@
177176
, totalSize: data.size
178177
}, _this, options);
179178
}
180-
}, false);
179+
}, 100), false);
181180
}
182181

183182
xhr.onreadystatechange = function (){
@@ -193,7 +192,7 @@
193192
}
194193
xhr.onreadystatechange = null;
195194

196-
if (!xhr.status || xhr.status - 201 > 0) {
195+
if( !xhr.status || xhr.status - 201 > 0 ){
197196
api.log("Error: " + xhr.status);
198197
// some kind of error
199198
// 0 - connection fail or timeout, if xhr.aborted is true, then it's not recoverable user action
@@ -212,6 +211,9 @@
212211
data.end = lkb;
213212
} else {
214213
data.end = data.start - 1;
214+
if (416 == xhr.status) {
215+
data.end = data.end - options.chunkSize;
216+
}
215217
}
216218

217219
setTimeout(function () {
@@ -243,7 +245,12 @@
243245
}, 0);
244246
}
245247
}
248+
246249
xhr = null;
250+
251+
if( slice ){
252+
slice = null;
253+
}
247254
}
248255
};
249256

@@ -253,13 +260,20 @@
253260
var slice;
254261
(slice = 'slice') in data.file || (slice = 'mozSlice') in data.file || (slice = 'webkitSlice') in data.file;
255262

256-
xhr.setRequestHeader("Content-Range", "bytes " + data.start + "-" + data.end + "/" + data.size);
257-
xhr.setRequestHeader("Content-Disposition", 'attachment; filename=' + encodeURIComponent(data.name));
258-
xhr.setRequestHeader("Content-Type", data.type || "application/octet-stream");
259-
260-
slice = data.file[slice](data.start, data.end + 1);
261-
262-
xhr.send(slice);
263+
slice = data.file[slice](data.start, data.end + 1);
264+
265+
if( data.size && !slice.size ){
266+
setTimeout(function (){
267+
_this.end(-1);
268+
});
269+
} else {
270+
xhr.setRequestHeader("Content-Range", "bytes " + data.start + "-" + data.end + "/" + data.size);
271+
xhr.setRequestHeader("Content-Disposition", 'attachment; filename=' + encodeURIComponent(data.name));
272+
xhr.setRequestHeader("Content-Type", data.type || "application/octet-stream");
273+
274+
xhr.send(slice);
275+
}
276+
263277
slice = null;
264278
} else {
265279
// single piece upload

0 commit comments

Comments
 (0)