Skip to content

Commit dfc5da2

Browse files
authored
Merge pull request #182 from codedogfish/master
fix fetch uphosts feature in IE
2 parents 716bff9 + b1963b1 commit dfc5da2

File tree

4 files changed

+93
-33
lines changed

4 files changed

+93
-33
lines changed

dist/qiniu.js

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* GitHub: http://github.com/qiniu/js-sdk
88
*
9-
* Date: 2016-9-12
9+
* Date: 2016-9-30
1010
*/
1111

1212
/*global plupload ,mOxie*/
@@ -599,22 +599,52 @@ function QiniuJsSDK() {
599599
var segments = uptoken.split(":");
600600
var ak = segments[0];
601601
var putPolicy = that.parseJSON(that.URLSafeBase64Decode(segments[2]));
602-
var uphosts_url = "https://uc.qbox.me/v1/query?ak="+ak+"&bucket="+putPolicy.scope;
602+
// var uphosts_url = "//uc.qbox.me/v1/query?ak="+ak+"&bucket="+putPolicy.scope;
603+
// IE 9- is not support protocal relative url
604+
var uphosts_url = window.location.protocol + "//uc.qbox.me/v1/query?ak="+ak+"&bucket="+putPolicy.scope;
603605
logger.debug("ak: ", ak);
604606
logger.debug("putPolicy: ", putPolicy);
605607
logger.debug("get uphosts from: ", uphosts_url);
606-
var ajax = that.createAjax();
607-
ajax.open('GET', uphosts_url, false);
608-
ajax.send();
609-
if (ajax.status === 200) {
610-
var res = that.parseJSON(ajax.responseText);
611-
qiniuUpHosts.http = getHosts(res.http.up);
612-
qiniuUpHosts.https = getHosts(res.https.up);
613-
logger.debug("get new uphosts: ", qiniuUpHosts);
614-
that.resetUploadUrl();
615-
} else {
616-
logger.error("get uphosts error: ", ajax.responseText);
608+
var ie = that.detectIEVersion();
609+
var ajax;
610+
if (ie && ie <= 9) {
611+
ajax = new mOxie.XMLHttpRequest();
612+
mOxie.Env.swf_url = op.flash_swf_url;
613+
}else{
614+
ajax = that.createAjax();
615+
}
616+
ajax.open('GET', uphosts_url, true);
617+
var onreadystatechange = function(){
618+
logger.debug("ajax.readyState: ", ajax.readyState);
619+
if (ajax.readyState === 4) {
620+
logger.debug("ajax.status: ", ajax.status);
621+
if (ajax.status < 400) {
622+
var res = that.parseJSON(ajax.responseText);
623+
qiniuUpHosts.http = getHosts(res.http.up);
624+
qiniuUpHosts.https = getHosts(res.https.up);
625+
logger.debug("get new uphosts: ", qiniuUpHosts);
626+
that.resetUploadUrl();
627+
} else {
628+
logger.error("get uphosts error: ", ajax.responseText);
629+
}
630+
}
631+
};
632+
if (ie && ie <= 9) {
633+
ajax.bind('readystatechange', onreadystatechange);
634+
}else{
635+
ajax.onreadystatechange = onreadystatechange;
617636
}
637+
ajax.send();
638+
// ajax.send();
639+
// if (ajax.status < 400) {
640+
// var res = that.parseJSON(ajax.responseText);
641+
// qiniuUpHosts.http = getHosts(res.http.up);
642+
// qiniuUpHosts.https = getHosts(res.https.up);
643+
// logger.debug("get new uphosts: ", qiniuUpHosts);
644+
// that.resetUploadUrl();
645+
// } else {
646+
// logger.error("get uphosts error: ", ajax.responseText);
647+
// }
618648
return;
619649
};
620650

@@ -926,7 +956,7 @@ function QiniuJsSDK() {
926956
directUpload(up, file, that.key_handler);
927957
} else {
928958
// TODO: need a polifill to make it work in IE 9-
929-
// ISSUE: if file.name is existed in localStorage
959+
// ISSUE: if file.name is existed in localStorage
930960
// but not the same file maybe cause error
931961
var localFileInfo = localStorage.getItem(file.name);
932962
var blockSize = chunk_size;
@@ -945,7 +975,7 @@ function QiniuJsSDK() {
945975

946976
if (localFileInfo.percent !== 100) {
947977
if (file.size === localFileInfo.total) {
948-
// TODO: if file.name and file.size is the same
978+
// TODO: if file.name and file.size is the same
949979
// but not the same file will cause error
950980
file.percent = localFileInfo.percent;
951981
file.loaded = localFileInfo.offset;
@@ -1226,7 +1256,7 @@ function QiniuJsSDK() {
12261256

12271257
var res = that.parseJSON(info.response);
12281258
ctx = ctx ? ctx : res.ctx;
1229-
// if ctx is not empty
1259+
// if ctx is not empty
12301260
// that means the upload strategy is chunk upload
12311261
// befroe the invoke the last_step
12321262
// we need request the mkfile to compose all uploaded chunks

0 commit comments

Comments
 (0)