Skip to content

Commit 87c4c54

Browse files
committed
Merge pull request #143 from codedogfish/udpate_documentation
Fix iOS get file name always same
2 parents 8bfe5be + 4b00c0c commit 87c4c54

File tree

8 files changed

+398
-221
lines changed

8 files changed

+398
-221
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
all : install build demo
1+
all : install build dev
22

33
install :
44
npm install

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ Qiniu-JavaScript-SDK 的示例 Demo 中的服务器端部分是基于[ Node.js
469469
```
470470
3. 进入项目根目录,执行 `make dev` 访问 `http://127.0.0.1:19110/` 或 `http://localhost:19110/`
471471
472+
<a id="note"></a>
472473
### 说明
473474
474475
1. JS-SDK 依赖 Plupload,初始化之前请引入 Plupload。
@@ -599,6 +600,7 @@ $('#stop_load').on('click', function(){
599600
600601
推荐一个关于 [CORS](http://enable-cors.org/) 的网站
601602
603+
<a id="contribute-code"></a>
602604
### 贡献代码
603605
604606
1. 登录 https://github.com
@@ -613,7 +615,7 @@ $('#stop_load').on('click', function(){
613615
614616
6. 然后到 github 网站的该 git 远程仓库的 new-feature 分支下发起 Pull Request
615617
616-
618+
<a id="license"></a>
617619
### 许可证
618620
619621
> Copyright (c) 2014 qiniu.com

demo/scripts/main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,22 @@ $(function() {
1414
flash_swf_url: 'bower_components/plupload/js/Moxie.swf',
1515
dragdrop: true,
1616
chunk_size: '4mb',
17+
multi_selection: !(mOxie.Env.OS.toLowerCase()==="ios"),
1718
uptoken_url: $('#uptoken_url').val(),
19+
// uptoken_func: function(){
20+
// var ajax = new XMLHttpRequest();
21+
// ajax.open('GET', $('#uptoken_url').val(), false);
22+
// ajax.setRequestHeader("If-Modified-Since", "0");
23+
// ajax.send();
24+
// if (ajax.status === 200) {
25+
// var res = JSON.parse(ajax.responseText);
26+
// console.log('custom uptoken_func:' + res.uptoken);
27+
// return res.uptoken;
28+
// } else {
29+
// console.log('custom uptoken_func err');
30+
// return '';
31+
// }
32+
// },
1833
domain: $('#domain').val(),
1934
get_new_uptoken: false,
2035
// downtoken_url: '/downtoken',

demo/views/index.html

Lines changed: 318 additions & 196 deletions
Large diffs are not rendered by default.

dist/qiniu.js

Lines changed: 30 additions & 11 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-3-22
9+
* Date: 2016-4-15
1010
*/
1111

1212
/*global plupload ,mOxie*/
@@ -102,25 +102,25 @@ function QiniuJsSDK() {
102102

103103
function log(type, args){
104104
var header = "[qiniu-js-sdk]["+type+"]";
105+
var msg = header;
106+
for (var i = 0; i < args.length; i++) {
107+
if (typeof args[i] === "string") {
108+
msg += " " + args[i];
109+
} else {
110+
msg += " " + that.stringifyJSON(args[i]);
111+
}
112+
}
105113
if (that.detectIEVersion()) {
106114
// http://stackoverflow.com/questions/5538972/console-log-apply-not-working-in-ie9
107115
//var log = Function.prototype.bind.call(console.log, console);
108116
//log.apply(console, args);
109-
var msg = header;
110-
for (var i = 0; i < args.length; i++) {
111-
msg+=that.stringifyJSON(args[i]);
112-
}
113117
console.log(msg);
114118
}else{
115119
args.unshift(header);
116120
console.log.apply(console, args);
117121
}
118122
if (document.getElementById('qiniu-js-sdk-log')) {
119-
var msg1 = header;
120-
for (var j = 0; j < args.length; j++) {
121-
msg1+=that.stringifyJSON(args[j]);
122-
}
123-
document.getElementById('qiniu-js-sdk-log').innerHTML += '<p>'+msg1+'</p>';
123+
document.getElementById('qiniu-js-sdk-log').innerHTML += '<p>'+msg+'</p>';
124124
}
125125
}
126126

@@ -515,7 +515,7 @@ function QiniuJsSDK() {
515515
};
516516

517517
// getUptoken maybe called at Init Event or BeforeUpload Event
518-
// case Init Event, the file param of getUptken will be set null value
518+
// case Init Event, the file param of getUptken will be set a null value
519519
// if op.uptoken has value, set uptoken with op.uptoken
520520
// else if op.uptoken_url has value, set uptoken from op.uptoken_url
521521
// else if op.uptoken_func has value, set uptoken by result of op.uptoken_func
@@ -665,6 +665,25 @@ function QiniuJsSDK() {
665665
auto_start = auto_start || (up.settings && up.settings.auto_start);
666666
logger.debug("auto_start: ", auto_start);
667667
logger.debug("files: ", files);
668+
669+
// detect is iOS
670+
var is_ios = function (){
671+
if(mOxie.Env.OS.toLowerCase()==="ios") {
672+
return true;
673+
} else {
674+
return false;
675+
}
676+
};
677+
678+
// if current env os is iOS change file name to [time].[ext]
679+
if (is_ios()) {
680+
for (var i = 0; i < files.length; i++) {
681+
var file = files[i];
682+
var ext = that.getFileExtension(file.name);
683+
file.name = file.id + "." + ext;
684+
}
685+
}
686+
668687
if (auto_start) {
669688
setTimeout(function(){
670689
up.start();

dist/qiniu.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/qiniu.min.map

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

src/qiniu.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,25 @@ function QiniuJsSDK() {
102102

103103
function log(type, args){
104104
var header = "[qiniu-js-sdk]["+type+"]";
105+
var msg = header;
106+
for (var i = 0; i < args.length; i++) {
107+
if (typeof args[i] === "string") {
108+
msg += " " + args[i];
109+
} else {
110+
msg += " " + that.stringifyJSON(args[i]);
111+
}
112+
}
105113
if (that.detectIEVersion()) {
106114
// http://stackoverflow.com/questions/5538972/console-log-apply-not-working-in-ie9
107115
//var log = Function.prototype.bind.call(console.log, console);
108116
//log.apply(console, args);
109-
var msg = header;
110-
for (var i = 0; i < args.length; i++) {
111-
msg+=that.stringifyJSON(args[i]);
112-
}
113117
console.log(msg);
114118
}else{
115119
args.unshift(header);
116120
console.log.apply(console, args);
117121
}
118122
if (document.getElementById('qiniu-js-sdk-log')) {
119-
var msg1 = header;
120-
for (var j = 0; j < args.length; j++) {
121-
msg1+=that.stringifyJSON(args[j]);
122-
}
123-
document.getElementById('qiniu-js-sdk-log').innerHTML += '<p>'+msg1+'</p>';
123+
document.getElementById('qiniu-js-sdk-log').innerHTML += '<p>'+msg+'</p>';
124124
}
125125
}
126126

@@ -515,7 +515,7 @@ function QiniuJsSDK() {
515515
};
516516

517517
// getUptoken maybe called at Init Event or BeforeUpload Event
518-
// case Init Event, the file param of getUptken will be set null value
518+
// case Init Event, the file param of getUptken will be set a null value
519519
// if op.uptoken has value, set uptoken with op.uptoken
520520
// else if op.uptoken_url has value, set uptoken from op.uptoken_url
521521
// else if op.uptoken_func has value, set uptoken by result of op.uptoken_func
@@ -665,6 +665,25 @@ function QiniuJsSDK() {
665665
auto_start = auto_start || (up.settings && up.settings.auto_start);
666666
logger.debug("auto_start: ", auto_start);
667667
logger.debug("files: ", files);
668+
669+
// detect is iOS
670+
var is_ios = function (){
671+
if(mOxie.Env.OS.toLowerCase()==="ios") {
672+
return true;
673+
} else {
674+
return false;
675+
}
676+
};
677+
678+
// if current env os is iOS change file name to [time].[ext]
679+
if (is_ios()) {
680+
for (var i = 0; i < files.length; i++) {
681+
var file = files[i];
682+
var ext = that.getFileExtension(file.name);
683+
file.name = file.id + "." + ext;
684+
}
685+
}
686+
668687
if (auto_start) {
669688
setTimeout(function(){
670689
up.start();

0 commit comments

Comments
 (0)