Skip to content

Commit

Permalink
优化例子指引
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Jan 11, 2019
1 parent ef0a02c commit 4131313
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions demo/demo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var config = {
Bucket: 'test-1250000000',
Bucket: 'test-1251902136',
Region: 'ap-guangzhou'
};

Expand Down Expand Up @@ -29,7 +29,9 @@ var camSafeUrlEncode = function (str) {

var getAuthorization = function (options, callback) {

// 方法一、后端通过获取临时密钥给到前端,前端计算签名
// 方法一、(推荐)后端通过获取临时密钥给到前端,前端计算签名
// 服务端 JS 和 PHP 例子:https://github.com/tencentyun/cos-js-sdk-v5/blob/master/server/
// 服务端其他语言参考 COS STS SDK :https://github.com/tencentyun/qcloud-cos-sts-sdk
// var url = 'http://127.0.0.1:3000/sts';
var url = '../server/sts.php';
var xhr = new XMLHttpRequest();
Expand All @@ -50,7 +52,8 @@ var getAuthorization = function (options, callback) {
xhr.send();


// // 方法二、【细粒度控制权限】后端通过获取临时密钥给到前端,前端只有相同请求才重用临时密钥,后端可以通过 Scope 细粒度控制权限
// // 方法二、(推荐)【细粒度控制权限】后端通过获取临时密钥给到前端,前端只有相同请求才重用临时密钥,后端可以通过 Scope 细粒度控制权限
// // 服务端例子:https://github.com/tencentyun/qcloud-cos-sts-sdk/edit/master/scope.md
// var url = 'http://127.0.0.1:3000/sts-scope';
// var xhr = new XMLHttpRequest();
// xhr.open('POST', url, true);
Expand All @@ -72,7 +75,8 @@ var getAuthorization = function (options, callback) {
// xhr.send(JSON.stringify(options.Scope));


// // 方法三、后端使用固定密钥计算签名,返回给前端,auth.php,注意:这种有安全风险,后端需要通过 method、pathname 控制好权限,比如不允许 put / 等,这里暂不提供
// //方法三、(不推荐,分片上传权限不好控制)后端使用固定密钥计算签名,返回给前端,auth.php,注意:这种有安全风险,后端需要通过 method、pathname 控制好权限,比如不允许 put / 等,这里暂不提供
// 服务端获取签名,请参考对应语言的 COS SDK:https://cloud.tencent.com/document/product/436/6474
// var method = (options.Method || 'get').toLowerCase();
// var query = options.Query || {};
// var headers = options.Headers || {};
Expand All @@ -97,7 +101,7 @@ var getAuthorization = function (options, callback) {
// xhr.send(JSON.stringify(data));


// // 方法四、前端使用固定密钥计算签名(适用于前端调试)
// //方法四、(不推荐,适用于前端调试)前端使用固定密钥计算签名
// var authorization = COS.getAuthorization({
// SecretId: 'AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
// SecretKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
Expand Down Expand Up @@ -572,6 +576,7 @@ function putObject() {
Region: config.Region,
Key: filename, /* 必须 */
Body: blob,
// 'Cache-Control': '',
TaskReady: function (tid) {
TaskId = tid;
},
Expand Down

0 comments on commit 4131313

Please sign in to comment.