Updated on 2024-11-13 GMT+08:00

Configuring an SDK Proxy (SDK for Node.js)

If you have any questions during development, post them on the Issues page of GitHub.

  1. In the root directory of the project, run the following command to download the proxy-agent dependency.

    npm install --save proxy-agent

  2. Declare and configure proxies in the project.

    const ProxyAgent = require("proxy-agent");
    const proxyAgent = new ProxyAgent(`http://username:password@proxyhost:proxyPort`);

  3. Initialize an ObsClient instance and configure a proxy.

    var obsClient = new ObsClient({
      // Obtain an AK/SK pair using environment variables or import an 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/intl/en-us/usermanual-ca/ca_01_0003.html.
      access_key_id: process.env.ACCESS_KEY_ID,
      secret_access_key: process.env.SECRET_ACCESS_KEY,
      // If you use a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
      security_token: process.env.SECURITY_TOKEN,
      // Enter the endpoint corresponding to the region where the bucket is located. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
      server: "https://obs.ap-southeast-1.myhuaweicloud.com"
      https_agent:proxyAgent,
      http_agent: proxyAgent,
    });