Skip to content

Commit 48653a5

Browse files
author
carsonxu
committed
支持 FollowRedirect 参数
1 parent fc7cc54 commit 48653a5

File tree

4 files changed

+18
-28
lines changed

4 files changed

+18
-28
lines changed

demo/demo.js

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var cos = new COS({
1717
ChunkSize: 1024 * 1024 * 8, // 控制分片大小,单位 B,在同园区上传可以设置较大的分片大小
1818
Proxy: '',
1919
Protocol: 'https:',
20+
FollowRedirect: false,
2021
});
2122

2223
var TaskId;
@@ -830,6 +831,14 @@ function putObjectCopy() {
830831
});
831832
}
832833

834+
cos.deleteObject({
835+
Bucket: config.Bucket,
836+
Region: config.Region,
837+
Key: 'pingjs/ext2020/qqindex2018/dist/img/qq_logo_2x.png',
838+
}, function (err, data) {
839+
getObject();
840+
});
841+
833842
function getObject() {
834843
var filepath1 = path.resolve(__dirname, '1mb.out1.zip');
835844
var filepath2 = path.resolve(__dirname, '1mb.out2.zip');
@@ -839,39 +848,16 @@ function getObject() {
839848
cos.getObject({
840849
Bucket: config.Bucket,
841850
Region: config.Region,
842-
Key: '1mb.zip',
851+
Key: 'pingjs/ext2020/qqindex2018/dist/img/qq_logo_2x.png',
843852
onProgress: function (progressData) {
844853
console.log(JSON.stringify(progressData));
845854
}
846855
}, function (err, data) {
847-
fs.writeFileSync(filepath1, data.Body);
856+
console.log(err);
857+
console.log(data);
858+
// fs.writeFileSync(filepath1, data.Body);
848859
});
849860

850-
// file2 获取对象到本地文件
851-
cos.getObject({
852-
Bucket: config.Bucket,
853-
Region: config.Region,
854-
Key: '1mb.zip',
855-
Output: fs.createWriteStream(filepath2),
856-
onProgress: function (progressData) {
857-
console.log(JSON.stringify(progressData));
858-
}
859-
}, function (err, data) {
860-
console.log(err || data);
861-
});
862-
863-
// file3 pipe 格式获取对象到本地文件
864-
var stream = cos.getObjectStream({
865-
Bucket: config.Bucket,
866-
Region: config.Region,
867-
Key: '1mb.zip',
868-
onProgress: function (progressData) {
869-
console.log(JSON.stringify(progressData));
870-
}
871-
}, function (err, data) {
872-
console.log(err || data);
873-
});
874-
stream.pipe(fs.createWriteStream(filepath3))
875861
}
876862

877863
function headObject() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cos-nodejs-sdk-v5",
3-
"version": "2.9.12",
3+
"version": "2.9.13",
44
"description": "cos nodejs sdk v5",
55
"main": "index.js",
66
"types": "types",

sdk/base.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3537,6 +3537,9 @@ function _submitRequest(params, callback) {
35373537
if (this.options.KeepAlive) {
35383538
opt.forever = true;
35393539
}
3540+
if (!this.options.FollowRedirect) {
3541+
opt.followRedirect = false;
3542+
}
35403543

35413544
// 修复 Content-Type: false 的 Bug,原因 request 模块会获取 request('mime-types).lookup(readStream.path) 作为 Content-Type
35423545
// 问题代码位置:https://github.com/request/request/blob/v2.88.1/request.js#L500

sdk/cos.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var defaultOptions = {
3838
Ip: '',
3939
StrictSsl: true,
4040
KeepAlive: true,
41+
FollowRedirect: true,
4142
UserAgent: '',
4243
ConfCwd: '',
4344
};

0 commit comments

Comments
 (0)