Skip to content

Commit

Permalink
修改 demo
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Aug 23, 2018
1 parent b100fb3 commit a05e5c2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
6 changes: 3 additions & 3 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var util = {
};

var cos = new COS({
FileParallelLimit: 5,
getAuthorization: function (options,callback) {
// 方法一、后端通过获取临时密钥给到前端,前端计算签名
// var url = 'http://127.0.0.1:3000/sts';
Expand Down Expand Up @@ -127,8 +126,8 @@ var showLogText = function (text, color) {

var logger = {
log: function (text) {
console.log(text);
showLogText(text);
console.log.apply(console, arguments);
showLogText([].join.call(arguments, ' '));
},
error: function (text) {
console.error(text);
Expand Down Expand Up @@ -626,6 +625,7 @@ function sliceUploadFile() {
TaskId = tid;
},
onHashProgress: function (progressData) {
logger.log('onHashProgress', JSON.stringify(progressData));
},
onProgress: function (progressData) {
logger.log('onProgress', JSON.stringify(progressData));
Expand Down
6 changes: 3 additions & 3 deletions demo/sts-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ <h1>Form 表单简单上传(兼容 IE8)</h1>
// 计算签名
var getAuthorization = function (options, callback) {
var method = (options.Method || 'get').toLowerCase();
var url = 'http://127.0.0.1:3000/sts-auth' +
// var url = '../server/sts-auth.php' +
// var url = 'http://127.0.0.1:3000/sts-auth' +
var url = '../server/sts-auth.php' +
'?method=' + method +
'&pathname=' + encodeURIComponent('/');
var xhr = new XMLHttpRequest();
Expand Down Expand Up @@ -90,7 +90,7 @@ <h1>Form 表单简单上传(兼容 IE8)</h1>
arr = items[i].split('=');
data[arr[0]] = decodeURIComponent(arr[1] || '');
}
showMessage(null, {url: prefix + Key, ETag: data.etag});
showMessage(null, {url: prefix + encodeURIComponent(Key).replace(/%2F/g, '/'), ETag: data.etag});
} else {
}
};
Expand Down
4 changes: 1 addition & 3 deletions demo/sts-post.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ <h1>Ajax Post 上传</h1>
// 上传文件
var uploadFile = function (file, callback) {
var Key = 'dir/' + file.name; // 这里指定上传目录和文件名

getAuthorization({Method: 'POST', Key: Key}, function (err, info) {
var fd = new FormData();
fd.append('key', Key);
Expand All @@ -77,7 +76,7 @@ <h1>Ajax Post 上传</h1>
xhr.onload = function () {
if (Math.floor(xhr.status / 100) === 2) {
var ETag = xhr.getResponseHeader('etag');
callback(null, {url: url, ETag: ETag});
callback(null, {url: prefix + encodeURIComponent(Key).replace(/%2F/g, '/'), ETag: ETag});
} else {
callback('文件 ' + Key + ' 上传失败,状态码:' + xhr.status);
}
Expand All @@ -86,7 +85,6 @@ <h1>Ajax Post 上传</h1>
callback('文件 ' + Key + ' 上传失败,请检查是否没配置 CORS 跨域规则');
};
xhr.send(fd);

});
};

Expand Down

0 comments on commit a05e5c2

Please sign in to comment.