Skip to content

Commit

Permalink
提供公共的 cos.request 方法
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Mar 17, 2021
1 parent 069754c commit 3c0bc2c
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 4 deletions.
17 changes: 17 additions & 0 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1382,10 +1382,27 @@ function deleteFolder() {
});
}

function request() {
cos.request({
Bucket: config.Bucket,
Region: config.Region,
Key: '1.txt',
Method: 'GET',
Action: 'acl',
Headers: {},
Query: {},
Body: '',
}, function (err, data) {
console.log('err:', err);
console.log('data:', data);
});
}

(function () {
var list = [
//'getService', // 不支持,正常场景会跨域
//'putBucket', // 不支持,正常场景会跨域
'request',
'getObjectUrl',
'getAuth',
'getBucket',
Expand Down
34 changes: 33 additions & 1 deletion dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2221,7 +2221,7 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '1.2.7';
COS.version = '1.2.8';

module.exports = COS;

Expand Down Expand Up @@ -7649,6 +7649,37 @@ function multipartAbort(params, callback) {
});
}

/**
* 抛弃分块上传
* @param {Object} params 参数对象,必须
* @param {String} params.Bucket Bucket名称,必须
* @param {String} params.Region 地域名称,必须
* @param {String} params.Key object名称,必须
* @param {String} params.UploadId 标示本次分块上传的ID,必须
* @param {Function} callback 回调函数,必须
* @return {Object} err 请求失败的错误,如果请求成功,则为空。https://cloud.tencent.com/document/product/436/7730
* @return {Object} data 返回的数据
*/
function request(params, callback) {
submitRequest.call(this, {
method: params.Method,
Bucket: params.Bucket,
Region: params.Region,
Key: params.Key,
action: params.Action,
headers: params.Headers,
qs: params.Query,
body: params.Body
}, function (err, data) {
if (err) return callback(err);
if (data && data.body) {
data.Body = data.body;
delete data.body;
}
callback(err, data);
});
}

/**
* 获取签名
* @param {Object} params 参数对象,必须
Expand Down Expand Up @@ -8327,6 +8358,7 @@ var API_MAP = {
multipartAbort: multipartAbort,

// 工具方法
request: request,
getObjectUrl: getObjectUrl,
getAuth: getAuth
};
Expand Down
2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-js-sdk-v5",
"version": "1.2.7",
"version": "1.2.8",
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
"main": "index.js",
"types": "types",
Expand Down
32 changes: 32 additions & 0 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2848,6 +2848,37 @@ function multipartAbort(params, callback) {
});
}

/**
* 抛弃分块上传
* @param {Object} params 参数对象,必须
* @param {String} params.Bucket Bucket名称,必须
* @param {String} params.Region 地域名称,必须
* @param {String} params.Key object名称,必须
* @param {String} params.UploadId 标示本次分块上传的ID,必须
* @param {Function} callback 回调函数,必须
* @return {Object} err 请求失败的错误,如果请求成功,则为空。https://cloud.tencent.com/document/product/436/7730
* @return {Object} data 返回的数据
*/
function request(params, callback) {
submitRequest.call(this, {
method: params.Method,
Bucket: params.Bucket,
Region: params.Region,
Key: params.Key,
action: params.Action,
headers: params.Headers,
qs: params.Query,
body: params.Body,
}, function (err, data) {
if (err) return callback(err);
if (data && data.body) {
data.Body = data.body;
delete data.body;
}
callback(err, data);
});
}

/**
* 获取签名
* @param {Object} params 参数对象,必须
Expand Down Expand Up @@ -3541,6 +3572,7 @@ var API_MAP = {
multipartAbort: multipartAbort,

// 工具方法
request: request,
getObjectUrl: getObjectUrl,
getAuth: getAuth,
};
Expand Down
2 changes: 1 addition & 1 deletion src/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '1.2.7';
COS.version = '1.2.8';

module.exports = COS;

0 comments on commit 3c0bc2c

Please sign in to comment.