Getting Started

Last updated: 2019-08-08 11:35:37

PDF

Preparations for Development

Obtain SDK

Download XML JS SDK resources for COS service on Github from: tencentyun/cos-nodejs-sdk-v5 .

Download Demo from XML Node.js SDK Demo .

Introduce npm

Before development, you need to install environment dependencies: npm address

npm i cos-nodejs-sdk-v5 --save

Development environment

  1. The use of SDK requires that your operating environment includes nodejs and npm. Nodejs 7.0 or above is recommended.
  2. After installing npm, be sure to install npm install once under SDK's decompressed directory (install dependency package).
  3. Go to Key Management on the console to obtain SecretId and SecretKey of your project.

For more information on the definitions of SecretId, SecretKey, Bucket and other terms and how to obtain them, please see COS Glossary.

Getting Started

  1. Go to the COS Console to create a bucket and obtain Bucket (bucket name) and Region (region name).
  2. Go to Key Management on the console to obtain SecretId and SecretKey of your project.
  3. Modify the SecretId, SecretKey, Bucket and Region to test the file upload by referring to the following code.
// Introduce the module
var COS = require('cos-nodejs-sdk-v5');
// Create an instance
var cos = new COS({
    AppId: '1250000000',
    SecretId: 'AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    SecretKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
});
// Multipart upload
cos.sliceUploadFile({
    Bucket: 'test',
    Region: 'ap-guangzhou',
    Key: '1.zip',
    FilePath: './1.zip'
}, function (err, data) {
    console.log(err, data);
});
  1. For more examples, please see XML Node.js SDK Demo.
  2. For the complete API documentation, please see XML Node.js SDK API documentation.