Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all : install build demo
all : install build dev

install :
npm install
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ Qiniu-JavaScript-SDK 的示例 Demo 中的服务器端部分是基于[ Node.js
```
3. 进入项目根目录,执行 `make dev` 访问 `http://127.0.0.1:19110/` 或 `http://localhost:19110/`

<a id="note"></a>
### 说明

1. JS-SDK 依赖 Plupload,初始化之前请引入 Plupload。
Expand Down Expand Up @@ -599,6 +600,7 @@ $('#stop_load').on('click', function(){

推荐一个关于 [CORS](http://enable-cors.org/) 的网站

<a id="contribute-code"></a>
### 贡献代码

1. 登录 https://github.com
Expand All @@ -613,7 +615,7 @@ $('#stop_load').on('click', function(){

6. 然后到 github 网站的该 git 远程仓库的 new-feature 分支下发起 Pull Request


<a id="license"></a>
### 许可证

> Copyright (c) 2014 qiniu.com
Expand Down
15 changes: 15 additions & 0 deletions demo/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,22 @@ $(function() {
flash_swf_url: 'bower_components/plupload/js/Moxie.swf',
dragdrop: true,
chunk_size: '4mb',
multi_selection: !(mOxie.Env.OS.toLowerCase()==="ios"),
uptoken_url: $('#uptoken_url').val(),
// uptoken_func: function(){
// var ajax = new XMLHttpRequest();
// ajax.open('GET', $('#uptoken_url').val(), false);
// ajax.setRequestHeader("If-Modified-Since", "0");
// ajax.send();
// if (ajax.status === 200) {
// var res = JSON.parse(ajax.responseText);
// console.log('custom uptoken_func:' + res.uptoken);
// return res.uptoken;
// } else {
// console.log('custom uptoken_func err');
// return '';
// }
// },
domain: $('#domain').val(),
get_new_uptoken: false,
// downtoken_url: '/downtoken',
Expand Down
514 changes: 318 additions & 196 deletions demo/views/index.html

Large diffs are not rendered by default.

41 changes: 30 additions & 11 deletions dist/qiniu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* GitHub: http://github.com/qiniu/js-sdk
*
* Date: 2016-3-22
* Date: 2016-4-15
*/

/*global plupload ,mOxie*/
Expand Down Expand Up @@ -102,25 +102,25 @@ function QiniuJsSDK() {

function log(type, args){
var header = "[qiniu-js-sdk]["+type+"]";
var msg = header;
for (var i = 0; i < args.length; i++) {
if (typeof args[i] === "string") {
msg += " " + args[i];
} else {
msg += " " + that.stringifyJSON(args[i]);
}
}
if (that.detectIEVersion()) {
// http://stackoverflow.com/questions/5538972/console-log-apply-not-working-in-ie9
//var log = Function.prototype.bind.call(console.log, console);
//log.apply(console, args);
var msg = header;
for (var i = 0; i < args.length; i++) {
msg+=that.stringifyJSON(args[i]);
}
console.log(msg);
}else{
args.unshift(header);
console.log.apply(console, args);
}
if (document.getElementById('qiniu-js-sdk-log')) {
var msg1 = header;
for (var j = 0; j < args.length; j++) {
msg1+=that.stringifyJSON(args[j]);
}
document.getElementById('qiniu-js-sdk-log').innerHTML += '<p>'+msg1+'</p>';
document.getElementById('qiniu-js-sdk-log').innerHTML += '<p>'+msg+'</p>';
}
}

Expand Down Expand Up @@ -515,7 +515,7 @@ function QiniuJsSDK() {
};

// getUptoken maybe called at Init Event or BeforeUpload Event
// case Init Event, the file param of getUptken will be set null value
// case Init Event, the file param of getUptken will be set a null value
// if op.uptoken has value, set uptoken with op.uptoken
// else if op.uptoken_url has value, set uptoken from op.uptoken_url
// else if op.uptoken_func has value, set uptoken by result of op.uptoken_func
Expand Down Expand Up @@ -665,6 +665,25 @@ function QiniuJsSDK() {
auto_start = auto_start || (up.settings && up.settings.auto_start);
logger.debug("auto_start: ", auto_start);
logger.debug("files: ", files);

// detect is iOS
var is_ios = function (){
if(mOxie.Env.OS.toLowerCase()==="ios") {
return true;
} else {
return false;
}
};

// if current env os is iOS change file name to [time].[ext]
if (is_ios()) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
var ext = that.getFileExtension(file.name);
file.name = file.id + "." + ext;
}
}

if (auto_start) {
setTimeout(function(){
up.start();
Expand Down
2 changes: 1 addition & 1 deletion dist/qiniu.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/qiniu.min.map

Large diffs are not rendered by default.

39 changes: 29 additions & 10 deletions src/qiniu.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,25 @@ function QiniuJsSDK() {

function log(type, args){
var header = "[qiniu-js-sdk]["+type+"]";
var msg = header;
for (var i = 0; i < args.length; i++) {
if (typeof args[i] === "string") {
msg += " " + args[i];
} else {
msg += " " + that.stringifyJSON(args[i]);
}
}
if (that.detectIEVersion()) {
// http://stackoverflow.com/questions/5538972/console-log-apply-not-working-in-ie9
//var log = Function.prototype.bind.call(console.log, console);
//log.apply(console, args);
var msg = header;
for (var i = 0; i < args.length; i++) {
msg+=that.stringifyJSON(args[i]);
}
console.log(msg);
}else{
args.unshift(header);
console.log.apply(console, args);
}
if (document.getElementById('qiniu-js-sdk-log')) {
var msg1 = header;
for (var j = 0; j < args.length; j++) {
msg1+=that.stringifyJSON(args[j]);
}
document.getElementById('qiniu-js-sdk-log').innerHTML += '<p>'+msg1+'</p>';
document.getElementById('qiniu-js-sdk-log').innerHTML += '<p>'+msg+'</p>';
}
}

Expand Down Expand Up @@ -515,7 +515,7 @@ function QiniuJsSDK() {
};

// getUptoken maybe called at Init Event or BeforeUpload Event
// case Init Event, the file param of getUptken will be set null value
// case Init Event, the file param of getUptken will be set a null value
// if op.uptoken has value, set uptoken with op.uptoken
// else if op.uptoken_url has value, set uptoken from op.uptoken_url
// else if op.uptoken_func has value, set uptoken by result of op.uptoken_func
Expand Down Expand Up @@ -665,6 +665,25 @@ function QiniuJsSDK() {
auto_start = auto_start || (up.settings && up.settings.auto_start);
logger.debug("auto_start: ", auto_start);
logger.debug("files: ", files);

// detect is iOS
var is_ios = function (){
if(mOxie.Env.OS.toLowerCase()==="ios") {
return true;
} else {
return false;
}
};

// if current env os is iOS change file name to [time].[ext]
if (is_ios()) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
var ext = that.getFileExtension(file.name);
file.name = file.id + "." + ext;
}
}

if (auto_start) {
setTimeout(function(){
up.start();
Expand Down