Skip to content

Commit cfa76f7

Browse files
committed
Merge pull request #36 from qiniupd/fix_499_in_another_way
Fix 499 bug
2 parents 24e18fb + 9860f8c commit cfa76f7

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

demo/js/qiniu.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,16 @@ function QiniuJsSDK() {
390390
var before = localFileInfo.time || 0;
391391
var aDay = 24 * 60 * 60 * 1000; // milliseconds
392392
if (now - before < aDay) {
393-
file.loaded = localFileInfo.offset;
394-
file.percent = localFileInfo.percent;
395-
ctx = localFileInfo.ctx;
396-
if (localFileInfo.offset + blockSize > file.size) {
397-
blockSize = file.size - localFileInfo.offset;
393+
if (localFileInfo.percent !== 100) {
394+
file.percent = localFileInfo.percent;
395+
file.loaded = localFileInfo.offset;
396+
ctx = localFileInfo.ctx;
397+
if (localFileInfo.offset + blockSize > file.size) {
398+
blockSize = file.size - localFileInfo.offset;
399+
}
400+
} else {
401+
// 删除localStorage,避免 499 bug
402+
localStorage.removeItem(file.name);
398403
}
399404
} else {
400405
localStorage.removeItem(file.name);
@@ -479,7 +484,7 @@ function QiniuJsSDK() {
479484
errorObj = that.parseJSON(errorObj.error);
480485
errorText = errorObj.error || 'file exists';
481486
} catch (e) {
482-
throw ('invalid json format');
487+
errorText = errorObj.error || 'file exists';
483488
}
484489
break;
485490
case 631:
@@ -589,10 +594,10 @@ function QiniuJsSDK() {
589594
ajax.setRequestHeader('Authorization', 'UpToken ' + that.token);
590595
ajax.onreadystatechange = function() {
591596
if (ajax.readyState === 4) {
597+
localStorage.removeItem(file.name);
592598
if (ajax.status === 200) {
593599
var info = ajax.responseText;
594600
last_step(up, file, info);
595-
localStorage.removeItem(file.name);
596601
} else {
597602
uploader.trigger('Error', {
598603
status: ajax.status,

src/qiniu.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,16 @@ function QiniuJsSDK() {
390390
var before = localFileInfo.time || 0;
391391
var aDay = 24 * 60 * 60 * 1000; // milliseconds
392392
if (now - before < aDay) {
393-
file.loaded = localFileInfo.offset;
394-
file.percent = localFileInfo.percent;
395-
ctx = localFileInfo.ctx;
396-
if (localFileInfo.offset + blockSize > file.size) {
397-
blockSize = file.size - localFileInfo.offset;
393+
if (localFileInfo.percent !== 100) {
394+
file.percent = localFileInfo.percent;
395+
file.loaded = localFileInfo.offset;
396+
ctx = localFileInfo.ctx;
397+
if (localFileInfo.offset + blockSize > file.size) {
398+
blockSize = file.size - localFileInfo.offset;
399+
}
400+
} else {
401+
// 进度100%时,删除对应的localStorage,避免 499 bug
402+
localStorage.removeItem(file.name);
398403
}
399404
} else {
400405
localStorage.removeItem(file.name);
@@ -479,7 +484,7 @@ function QiniuJsSDK() {
479484
errorObj = that.parseJSON(errorObj.error);
480485
errorText = errorObj.error || 'file exists';
481486
} catch (e) {
482-
throw ('invalid json format');
487+
errorText = errorObj.error || 'file exists';
483488
}
484489
break;
485490
case 631:
@@ -589,10 +594,10 @@ function QiniuJsSDK() {
589594
ajax.setRequestHeader('Authorization', 'UpToken ' + that.token);
590595
ajax.onreadystatechange = function() {
591596
if (ajax.readyState === 4) {
597+
localStorage.removeItem(file.name);
592598
if (ajax.status === 200) {
593599
var info = ajax.responseText;
594600
last_step(up, file, info);
595-
localStorage.removeItem(file.name);
596601
} else {
597602
uploader.trigger('Error', {
598603
status: ajax.status,

0 commit comments

Comments
 (0)