Skip to content

Commit

Permalink
修复 getObject 问题
Browse files Browse the repository at this point in the history
  • Loading branch information
annexwu committed Aug 15, 2019
1 parent 5489730 commit f7fd3e7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
9 changes: 8 additions & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,14 @@ var logger = {
var args = [].map.call(arguments, function (v) {
return typeof v === 'object' ? JSON.stringify(v) : v;
});
showLogText(args.join(' '));

var logStr = args.join(' ');

if(logStr.length > 10000) {
logStr = logStr.slice(0, 10000) + '...content is too long, the first 10000 characters are intercepted';
}

showLogText(logStr);
},
error: function (text) {
console.error(text);
Expand Down
38 changes: 21 additions & 17 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -4589,7 +4589,7 @@ function deleteBucketTagging(params, callback) {
function putBucketLifecycle(params, callback) {

var LifecycleConfiguration = params['LifecycleConfiguration'] || {};
var Rules = LifecycleConfiguration.Rules || [];
var Rules = LifecycleConfiguration.Rules || params.Rules || [];
Rules = util.clone(Rules);
var xml = util.json2xml({ LifecycleConfiguration: { Rule: Rules } });

Expand Down Expand Up @@ -4963,20 +4963,23 @@ function getObject(params, callback) {
* @param {String} params.Bucket Bucket名称,必须
* @param {String} params.Region 地域名称,必须
* @param {String} params.Key 文件名称,必须
* @param {File || Blob || String} params.Body 上传文件对象或字符串
* @param {File || Blob || String} params.Body 上传文件对象或字符串,必须
* @param {String} params.CacheControl RFC 2616 中定义的缓存策略,将作为 Object 元数据保存,非必须
* @param {String} params.ContentDisposition RFC 2616 中定义的文件名称,将作为 Object 元数据保存,非必须
* @param {String} params.ContentEncoding RFC 2616 中定义的编码格式,将作为 Object 元数据保存,非必须
* @param {String} params.ContentLength RFC 2616 中定义的 HTTP 请求内容长度(字节),必须
* @param {String} params.ContentType RFC 2616 中定义的内容类型(MIME),将作为 Object 元数据保存,非必须
* @param {String} params.Expect 当使用 Expect: 100-continue 时,在收到服务端确认后,才会发送请求内容,非必须
* @param {String} params.Expires RFC 2616 中定义的过期时间,将作为 Object 元数据保存,非必须
* @param {String} params.ContentSha1 RFC 3174 中定义的 160-bit 内容 SHA-1 算法校验,非必须
* @param {String} params.ACL 允许用户自定义文件权限,有效值:private | public-read,非必须
* @param {String} params.GrantRead 赋予被授权者读的权限,格式 x-cos-grant-read: uin=" ",uin=" ",非必须
* @param {String} params.GrantWrite 赋予被授权者写的权限,格式 x-cos-grant-write: uin=" ",uin=" ",非必须
* @param {String} params.GrantFullControl 赋予被授权者读写权限,格式 x-cos-grant-full-control: uin=" ",uin=" ",非必须
* @param {String} params.ServerSideEncryption 支持按照指定的加密算法进行服务端数据加密,格式 x-cos-server-side-encryption: "AES256",非必须
* @param {String} params.GrantRead 赋予被授权者读取对象的权限,格式:id="[OwnerUin]",可使用半角逗号(,)分隔多组被授权者,非必须
* @param {String} params.GrantReadAcp 赋予被授权者读取对象的访问控制列表(ACL)的权限,格式:id="[OwnerUin]",可使用半角逗号(,)分隔多组被授权者,非必须
* @param {String} params.GrantWriteAcp 赋予被授权者写入对象的访问控制列表(ACL)的权限,格式:id="[OwnerUin]",可使用半角逗号(,)分隔多组被授权者,非必须
* @param {String} params.GrantFullControl 赋予被授权者操作对象的所有权限,格式:id="[OwnerUin]",可使用半角逗号(,)分隔多组被授权者,非必须
* @param {String} params.StorageClass 设置对象的存储级别,枚举值:STANDARD、STANDARD_IA、ARCHIVE,默认值:STANDARD,非必须
* @param {String} params.x-cos-meta-* 允许用户自定义的头部信息,将作为对象的元数据保存。大小限制2KB,非必须
* @param {String} params.ContentSha1 RFC 3174 中定义的 160-bit 内容 SHA-1 算法校验,非必须
* @param {String} params.ServerSideEncryption 支持按照指定的加密算法进行服务端数据加密,格式 x-cos-server-side-encryption: "AES256",非必须
* @param {Function} params.onProgress 上传进度回调函数
* @param {Function} callback 回调函数,必须
* @return {Object} err 请求失败的错误,如果请求成功,则为空。https://cloud.tencent.com/document/product/436/7730
Expand Down Expand Up @@ -6283,10 +6286,17 @@ function _submitRequest(params, callback) {
}

var jsonRes;
try {
jsonRes = body && body.indexOf('<') > -1 && body.indexOf('>') > -1 && util.xml2json(body) || {};
} catch (e) {
jsonRes = body || {};

// 不对 body 进行转换,body 直接挂载返回
if (rawBody) {
jsonRes = {};
jsonRes.body = body;
} else {
try {
jsonRes = body && body.indexOf('<') > -1 && body.indexOf('>') > -1 && util.xml2json(body) || {};
} catch (e) {
jsonRes = body || {};
}
}

// 请求返回码不为 200
Expand All @@ -6297,12 +6307,6 @@ function _submitRequest(params, callback) {
return;
}

// 不对 body 进行转换,body 直接挂载返回
if (rawBody) {
jsonRes = {};
jsonRes.body = body;
}

if (jsonRes.Error) {
cb({ error: jsonRes.Error });
return;
Expand Down
20 changes: 11 additions & 9 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2321,10 +2321,17 @@ function _submitRequest(params, callback) {
}

var jsonRes;
try {
jsonRes = body && body.indexOf('<') > -1 && body.indexOf('>') > -1 && util.xml2json(body) || {};
} catch (e) {
jsonRes = body || {};

// 不对 body 进行转换,body 直接挂载返回
if(rawBody) {
jsonRes = {};
jsonRes.body = body;
} else {
try {
jsonRes = body && body.indexOf('<') > -1 && body.indexOf('>') > -1 && util.xml2json(body) || {};
} catch (e) {
jsonRes = body || {};
}
}

// 请求返回码不为 200
Expand All @@ -2335,11 +2342,6 @@ function _submitRequest(params, callback) {
return;
}

// 不对 body 进行转换,body 直接挂载返回
if (rawBody) {
jsonRes = {};
jsonRes.body = body;
}

if (jsonRes.Error) {
cb({error: jsonRes.Error});
Expand Down

0 comments on commit f7fd3e7

Please sign in to comment.