Skip to content

Commit

Permalink
优化 demo、test
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Nov 21, 2018
1 parent bf218ca commit 15e56b5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 80 deletions.
37 changes: 4 additions & 33 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var util = {

var cos = new COS({
getAuthorization: function (options,callback) {

// 方法一、后端通过获取临时密钥给到前端,前端计算签名
// var url = 'http://127.0.0.1:3000/sts';
var url = '../server/sts.php';
Expand All @@ -39,37 +40,7 @@ var cos = new COS({
xhr.send();


// // 方法二、后端通过获取临时密钥,并计算好签名给到前端
// var method = (options.Method || 'get').toLowerCase();
// var key = options.Key || '';
// var query = options.Query || {};
// var headers = options.Headers || {};
// var pathname = key.indexOf('/') === 0 ? key : '/' + key;
// // var url = 'http://127.0.0.1:3000/sts-auth';
// var url = '../server/sts-auth.php';
// var xhr = new XMLHttpRequest();
// var data = {
// method: method,
// pathname: pathname,
// query: query,
// headers: headers,
// };
// xhr.open('POST', url, true);
// xhr.setRequestHeader('content-type', 'application/json');
// xhr.onload = function (e) {
// try {
// var AuthData = JSON.parse(e.target.responseText);
// } catch (e) {
// }
// callback({
// Authorization: AuthData.Authorization,
// XCosSecurityToken: AuthData.XCosSecurityToken,
// });
// };
// xhr.send(JSON.stringify(data));


// // 方法三、后端使用固定密钥计算签名,返回给前端,auth.php,注意:后端需要通过 method、pathname 控制好权限,比如不允许 put / 等,这里暂不提供
// // 方法二、后端使用固定密钥计算签名,返回给前端,auth.php,注意:后端需要通过 method、pathname 控制好权限,比如不允许 put / 等,这里暂不提供
// var method = (options.Method || 'get').toLowerCase();
// var key = options.Key || '';
// var query = options.Query || {};
Expand All @@ -92,7 +63,7 @@ var cos = new COS({
// xhr.send(JSON.stringify(data));


// // 方法四、前端使用固定密钥计算签名(适用于前端调试)
// // 方法三、前端使用固定密钥计算签名(适用于前端调试)
// var authorization = COS.getAuthorization({
// SecretId: 'AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
// SecretKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
Expand Down Expand Up @@ -552,7 +523,7 @@ function deleteBucket() {

function putObject() {
// 创建测试文件
var filename = '1mb.zip';
var filename = '(!\'*) "#$%&+,-./0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
var blob = util.createFile({size: 1024 * 1024 * 1});
// 调用方法
cos.putObject({
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"scripts": {
"dev": "SET NODE_ENV=development&& webpack -w",
"build": "SET NODE_ENV=production&& webpack",
"sts.js": "node server/sts.js",
"sts-auth.js": "node server/sts-auth.js"
"sts.js": "node server/sts.js"
},
"repository": {
"type": "git",
Expand Down
45 changes: 0 additions & 45 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ var util = {
};

var getAuthorization = function (options, callback) {

// 方法一、后端通过获取临时密钥,计算签名给到前端(适用于前端调试)
// var url = 'http://127.0.0.1:3000/sts?Bucket=' + options.Bucket + '&Region=' + options.Region;
// var url = '../server/sts.php?Bucket=' + options.Bucket + '&Region=' + options.Region;
var url = '../server/sts.php';
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
Expand All @@ -48,47 +44,6 @@ var getAuthorization = function (options, callback) {
});
};
xhr.send();


// // 方法二、后端通过获取临时密钥,计算签名给到前端(适用于前端调试)
// var method = (options.Method || 'get').toLowerCase();
// var key = options.Key || '';
// var query = options.Query || {};
// var headers = options.Headers || {};
// var pathname = key.indexOf('/') === 0 ? key : '/' + key;
// // var url = 'http://127.0.0.1:3000/sts-auth';
// var url = '../server/sts-auth.php';
// var xhr = new XMLHttpRequest();
// var data = {
// method: method,
// pathname: pathname,
// query: query,
// headers: headers,
// };
// xhr.open('POST', url, true);
// xhr.setRequestHeader('content-type', 'application/json');
// xhr.onload = function (e) {
// try {
// var AuthData = JSON.parse(e.target.responseText);
// } catch (e) {
// }
// callback({
// Authorization: AuthData.Authorization,
// XCosSecurityToken: AuthData.XCosSecurityToken,
// });
// };
// xhr.send(JSON.stringify(data));


// // 方法三、前端计算签名(适用于前端调试)
// var authorization = COS.getAuthorization({
// SecretId: 'AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
// SecretKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
// Method: options.Method,
// Key: options.Key,
// });
// callback(authorization);

};
var dataURItoUploadBody = function (dataURI) {
var byteString = atob(dataURI.split(',')[1]);
Expand Down

0 comments on commit 15e56b5

Please sign in to comment.