Help Center/ OBS Nodejs SDK/ API Reference/ Initialization/ Initializing an ObsClient Instance
Updated on 2023-11-09 GMT+08:00

Initializing an ObsClient Instance

API Description

ObsClient functions as the Node.js client for accessing OBS. It offers callers a series of APIs for interaction with OBS and is used for managing and operating resources, such as buckets and objects, stored in OBS.

Method Definition

1. Constructor form: ObsClient(parameter)
2. Factory method form: ObsClient.factory(parameter)

Parameter Description

Field

Type

Optional or Mandatory

Description

access_key_id

String

Optional

AK

secret_access_key

String

Optional

SK

server

String

Mandatory

Endpoint for accessing OBS, which contains the protocol type, domain name (or IP address), and port number. For example, https://your-endpoint:443.

max_retry_count

Number

Optional

Maximum number of retries when an HTTP/HTTPS connection is abnormal. The default value is 3.

timeout

Number

Optional

Timeout period (in seconds) of an HTTP/HTTPS request. The default value is 60.

ssl_verify

Boolean

or

String

Optional

Whether to verify the server certificate. Possible values are:

  • Path to the server-side root certificate file in .pem format
  • true: The default CAs are used to verify the server-side certificate.
  • false: The server-side certificates will not be verified.

The default value is false.

long_conn_param

Number

Optional

Persistent connection mode (in seconds) If the value is equal to or larger than 0, the persistent connection mode is enabled and this value is used as the initial delay of the TCP Keep-Alive packets.

By default, this parameter is left blank, which indicates that persistent connection mode is disabled.

is_cname

Boolean

Optional

Whether to use self-defined domain name to access OBS. The default value is false.

Sample Code

// Introduce the OBS library.
// Use npm to install the client.
var ObsClient = require('esdk-obs-nodejs');
var ProxyAgent = require('proxy-agent');
// Use the source code to install the client.
// var ObsClient = require('./lib/obs');

// Create an ObsClient instance.
var obsClient = new ObsClient({
       //Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
       //Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/eu/usermanual-ca/ca_01_0003.html.
       access_key_id: process.env.ACCESS_KEY_ID,
       secret_access_key: process.env.SECRET_ACCESS_KEY,
    //EU-Dublin region is used here as an example. Replace it with the one in your actual situation.
       server: 'https://obs.eu-west-101.myhuaweicloud.com'
       
       max_retry_count : 1,
       timeout : 20,
       ssl_verify : false,
       long_conn_param : 0,
       
});