cos-nodejs-sdk-v5
Advanced tools
Comparing version 1.1.0 to 1.1.3
var config = { | ||
AppId: '1250000000', | ||
SecretId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | ||
SecretKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | ||
SecretId: 'AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | ||
SecretKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | ||
Bucket: 'test', | ||
Region: 'cn-south' | ||
}; | ||
module.exports = config; |
131
demo/demo.js
@@ -7,6 +7,10 @@ var fs = require('fs'); | ||
var cos = new COS(config); | ||
var cos = new COS({ | ||
AppId: config.AppId, | ||
SecretId: config.SecretId, | ||
SecretKey: config.SecretKey, | ||
}); | ||
function getService() { | ||
cos.getService({}, function (err, data) { | ||
cos.getService(function (err, data) { | ||
return console.log(err || data); | ||
@@ -23,4 +27,4 @@ }); | ||
cos.putObject({ | ||
Bucket: 'test', /* 必须 */ | ||
Region: 'cn-south', | ||
Bucket: config.Bucket, /* 必须 */ | ||
Region: config.Region, | ||
Key: filename, /* 必须 */ | ||
@@ -41,4 +45,4 @@ Body: fs.createReadStream(filepath), /* 必须 */ | ||
cos.deleteObject({ | ||
Bucket: 'test', | ||
Region: 'cn-south', | ||
Bucket: config.Bucket, | ||
Region: config.Region, | ||
Key: '1mb.zip' | ||
@@ -54,6 +58,22 @@ }, function (err, data) { | ||
function deleteMultipleObject() { | ||
cos.deleteMultipleObject({ | ||
Bucket: config.Bucket, | ||
Region: config.Region, | ||
Objects : [ | ||
{Key : '1mb.zip'}, | ||
{Key : '3mb.zip'}, | ||
] | ||
}, function (err, data) { | ||
if (err) { | ||
return console.log(err); | ||
} | ||
console.log(JSON.stringify(data, null, ' ')); | ||
}); | ||
} | ||
function getBucket() { | ||
cos.getBucket({ | ||
Bucket: 'test', | ||
Region: 'cn-south' | ||
Bucket: config.Bucket, | ||
Region: config.Region | ||
}, function (err, data) { | ||
@@ -70,4 +90,4 @@ if (err) { | ||
cos.headBucket({ | ||
Bucket: 'test', | ||
Region: 'cn-south' | ||
Bucket: config.Bucket, | ||
Region: config.Region | ||
}, function (err, data) { | ||
@@ -83,4 +103,4 @@ if (err) { | ||
cos.putBucket({ | ||
Bucket: 'test-new', | ||
Region: 'cn-south' | ||
Bucket: 'testnew', | ||
Region: config.Region | ||
}, function (err, data) { | ||
@@ -96,4 +116,4 @@ if (err) { | ||
cos.deleteBucket({ | ||
Bucket: 'test-new', | ||
Region: 'cn-south' | ||
Bucket: 'testnew', | ||
Region: config.Region | ||
}, function (err, data) { | ||
@@ -109,4 +129,4 @@ if (err) { | ||
cos.getBucketACL({ | ||
Bucket: 'test', | ||
Region: 'cn-south' | ||
Bucket: config.Bucket, | ||
Region: config.Region | ||
}, function (err, data) { | ||
@@ -124,7 +144,7 @@ if (err) { | ||
cos.putBucketACL({ | ||
Bucket: 'test', | ||
Region: 'cn-south', | ||
//GrantWrite : 'uin="1111", uin="2222"', | ||
ACL: 'public-read', | ||
// ACL: 'private' | ||
Bucket: config.Bucket, | ||
Region: config.Region, | ||
// GrantWrite : 'uin="1111", uin="2222"', | ||
// ACL: 'public-read', | ||
ACL: 'private' | ||
}, function (err, data) { | ||
@@ -141,4 +161,4 @@ if (err) { | ||
cos.getBucketCORS({ | ||
Bucket: 'test', | ||
Region: 'cn-south' | ||
Bucket: config.Bucket, | ||
Region: config.Region | ||
}, function (err, data) { | ||
@@ -155,7 +175,7 @@ if (err) { | ||
cos.putBucketCORS({ | ||
Bucket: 'test', | ||
Region: 'cn-south', | ||
Bucket: config.Bucket, | ||
Region: config.Region, | ||
CORSRules: [{ | ||
"AllowedOrigin": ["*"], | ||
"AllowedMethod": ["PUT", "GET", "POST", "DELETE", "HEAD"], | ||
"AllowedMethod": ["GET", "POST", "PUT", "DELETE", "HEAD"], | ||
"AllowedHeader": ["origin", "accept", "content-type", "authorzation"], | ||
@@ -169,3 +189,2 @@ "ExposeHeader": ["ETag"], | ||
} | ||
console.log(JSON.stringify(data, null, ' ')); | ||
@@ -177,4 +196,4 @@ }); | ||
cos.getBucketLocation({ | ||
Bucket: 'test', | ||
Region: 'cn-south' | ||
Bucket: config.Bucket, | ||
Region: config.Region | ||
}, function (err, data) { | ||
@@ -184,2 +203,3 @@ if (err) { | ||
} | ||
console.log(JSON.stringify(data, null, ' ')); | ||
}); | ||
@@ -190,4 +210,4 @@ } | ||
cos.getObject({ | ||
Bucket: 'test', | ||
Region: 'cn-south', | ||
Bucket: config.Bucket, | ||
Region: config.Region, | ||
Key: '1mb.zip', | ||
@@ -205,4 +225,4 @@ Output: fs.createWriteStream(path.resolve(__dirname, '1mb.out.zip')) | ||
cos.headObject({ | ||
Bucket: 'test', | ||
Region: 'cn-south', | ||
Bucket: config.Bucket, | ||
Region: config.Region, | ||
Key: '1mb.zip' | ||
@@ -217,8 +237,6 @@ }, function (err, data) { | ||
var util = require('util'); | ||
var inspect = require('eyes').inspector({maxLength: false}) | ||
function getObjectACL() { | ||
cos.getObjectACL({ | ||
Bucket: 'test', | ||
Region: 'cn-south', | ||
Bucket: config.Bucket, | ||
Region: config.Region, | ||
Key: '1mb.zip' | ||
@@ -236,8 +254,9 @@ }, function (err, data) { | ||
var filename = '3mb.zip'; | ||
util.createFile(path.resolve(__dirname, filename), 1024 * 1024 * 3, function (err) { | ||
var filepath = path.resolve(__dirname, filename); | ||
util.createFile(filepath, 1024 * 1024 * 3, function (err) { | ||
// 调用方法 | ||
cos.sliceUploadFile({ | ||
Bucket: 'test', /* 必须 */ | ||
Region: 'cn-south', | ||
Key: 'p.exe', /* 必须 */ | ||
Bucket: config.Bucket, /* 必须 */ | ||
Region: config.Region, | ||
Key: filename, /* 必须 */ | ||
FilePath: filepath, /* 必须 */ | ||
@@ -282,8 +301,9 @@ SliceSize: 1024 * 1024, //1MB /* 非必须 */ | ||
], | ||
"resource": ["qcs::cos:cn-south:uid/1250000000:test-1250000000.cn-south.myqcloud.com//1250000000/test/*"] // 1250000000 是 appid | ||
// "resource": ["qcs::cos:cn-south:uid/1250000000:test-1250000000.cn-south.myqcloud.com//1250000000/test/*"] // 1250000000 是 appid | ||
"resource": ["qcs::cos:" + config.Region + ":uid/" + config.AppId + ":" + config.Bucket + "-" + config.AppId + "." + config.Region + ".myqcloud.com//" + config.AppId + "/" + config.Bucket + "/*"] // 1250000000 是 appid | ||
} | ||
] | ||
}, | ||
Bucket: 'test', | ||
Region: 'cn-south' | ||
Bucket: config.Bucket, | ||
Region: config.Region | ||
}, function (err, data) { | ||
@@ -300,4 +320,4 @@ if (err) { | ||
cos.getBucketPolicy({ | ||
Bucket: 'test', | ||
Region: 'cn-south' | ||
Bucket: config.Bucket, | ||
Region: config.Region | ||
}, function (err, data) { | ||
@@ -314,6 +334,6 @@ if (err) { | ||
cos.putObjectCopy({ | ||
Bucket: 'test', | ||
Region: 'cn-south', | ||
Bucket: config.Bucket, | ||
Region: config.Region, | ||
Key: '1mb.copy.zip', | ||
CopySource: 'test-1251902136.cn-south.myqcloud.com/1mb.zip', | ||
CopySource: config.Bucket + '-' + config.AppId + '.' + config.Region + '.myqcloud.com/1mb.zip', | ||
}, function (err, data) { | ||
@@ -328,3 +348,13 @@ if (err) { | ||
function getAuth() { | ||
var key = '1mb.zip'; | ||
var auth = cos.getAuth({ | ||
Method: 'get', | ||
Key: key | ||
}); | ||
console.log('http://' + config.Bucket + '-' + config.AppId + '.' + config.Region + '.myqcloud.com/' + key + '?sign=' + encodeURIComponent(auth)); | ||
} | ||
getService(); | ||
// getAuth(); | ||
// getBucket(); | ||
@@ -346,3 +376,4 @@ // headBucket(); | ||
// deleteObject(); | ||
// deleteMultipleObject(); | ||
// getObjectACL(); | ||
// sliceUploadFile(); | ||
// sliceUploadFile(); |
{ | ||
"name": "cos-nodejs-sdk-v5", | ||
"version": "1.1.0", | ||
"version": "1.1.3", | ||
"description": "cos nodejs sdk v5", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# cos-nodejs-sdk-v5 | ||
cos nodejs sdk for XML API | ||
腾讯云 COS Nodejs SDK([XML API](https://www.qcloud.com/document/product/436/7751)) | ||
## 使用说明 | ||
[releases](https://github.com/tencentyun/cos-nodejs-sdk-v5/releases) | ||
https://www.qcloud.com/document/product/436/8629 | ||
## 使用文档 | ||
https://www.qcloud.com/document/product/436/8629 | ||
## npm 安装 | ||
``` | ||
npm i cos-nodejs-sdk-v5 --save | ||
``` | ||
## get started | ||
```javascript | ||
var COS = require('cos-nodejs-sdk-v5'); | ||
var cos = new COS({ | ||
AppId: '1250000000', | ||
SecretId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', | ||
SecretKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', | ||
}); | ||
// 分片上传 | ||
cos.sliceUploadFile({ | ||
Bucket: 'test', | ||
Region: 'cn-south', | ||
Key: '1.zip', | ||
FilePath: './1.zip' | ||
}, function (err, data) { | ||
console.log(err, data); | ||
}); | ||
``` |
@@ -210,3 +210,3 @@ var fs = require('fs'); | ||
self.MultipartList(params, function (err, data) { | ||
self.multipartList(params, function (err, data) { | ||
if (err) { | ||
@@ -255,3 +255,3 @@ return callback(err); | ||
// 不存在 UploadId, 直接初始化生成 UploadId | ||
self.MultipartInit({ | ||
self.multipartInit({ | ||
Bucket: Bucket, | ||
@@ -316,3 +316,3 @@ Region: Region, | ||
self.MultipartListPart({ | ||
self.multipartListPart({ | ||
Bucket: Bucket, | ||
@@ -604,3 +604,3 @@ Region: Region, | ||
self.MultipartUpload({ | ||
self.multipartUpload({ | ||
Bucket: Bucket, | ||
@@ -645,3 +645,3 @@ Region: Region, | ||
self.MultipartComplete({ | ||
self.multipartComplete({ | ||
Bucket: Bucket, | ||
@@ -769,3 +769,3 @@ Region: Region, | ||
self.MultipartAbort({ | ||
self.multipartAbort({ | ||
Bucket: Bucket, | ||
@@ -772,0 +772,0 @@ Region: Region, |
@@ -10,3 +10,3 @@ 'use strict'; | ||
options = options || {}; | ||
this.Appid = options.AppId || options.Appid; | ||
this.AppId = options.AppId; | ||
this.SecretId = options.SecretId; | ||
@@ -13,0 +13,0 @@ this.SecretKey = options.SecretKey; |
@@ -71,3 +71,2 @@ 'use strict'; | ||
// 步骤二:构成 FormatString | ||
@@ -85,3 +84,3 @@ var formatString = [method, pathname, obj2str(queryParams), obj2str(headers), ''].join('\n'); | ||
// 步骤四:计算 Signature | ||
var qSignature = crypto.createHmac('sha1', signKey).update(stringToSign).digest('hex');//CryptoJS.HmacSHA1(stringToSign, signKey).toString(); | ||
var qSignature = crypto.createHmac('sha1', signKey).update(stringToSign).digest('hex'); | ||
@@ -88,0 +87,0 @@ // 步骤五:构造 Authorization |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
36
1
110124
2785