Updated on 2024-04-26 GMT+08:00

Methods

If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference.

If problems occur when using the OBS BrowserJS SDK, you can perform the following steps to analyze and locate the problems.

  1. Make sure that the OBS BrowserJS SDK is the latest version. Download the latest version.
  2. Make sure that the program code of the OBS BrowserJS SDK complies with General Examples of ObsClient. All ObsClient APIs are processed with exception handling. The following is an example code of uploading an object:

    // Create an ObsClient instance.
    var obsClient = new ObsClient({
        // Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables AccessKeyID and SecretAccessKey.
        // The front-end code does not have the process environment variable, so you need to use a module bundler like webpack to define the process variable.
        // 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.AccessKeyID,
        secret_access_key: process.env.SecretAccessKey,
        // Replace the example endpoint with the actual one in your case.
        server: 'https://obs.ap-southeast-1.myhuaweicloud.com'
    });
    
    obsClient.putObject({
           Bucket : 'bucketname',
           Key : 'objectname',
           Body : 'Hello OBS'
    }, function (err, result) {
           if(err){
                  // If there are any error messages displayed, there is something wrong with the API call. The common cause is a network exception.
                  console.error('Error-->' + err);
           }else{
                  // If there are no error messages displayed, the API call is complete. Then, check the HTTP status code using the SDK common result.
                  if(result.CommonMsg.Status < 300){// If the HTTP status code is less than 300, and the API call is successful.
                         if(result.InterfaceResult){
                               // Process the business logic after the call is successful.
                               // Optional: After the API is successfully called, record the HTTP status code and request ID returned by the server.
                               console.log('Status-->' + result.CommonMsg.Status);
                               console.log('RequestId-->' + result.CommonMsg.RequestId);
                         }
                  }else{
                         // Recommended: If the call fails, record the HTTP status code, server-side error code, and request ID returned by the server.
                         console.log('Status-->' + result.CommonMsg.Status);
                         console.log('Code-->' + result.CommonMsg.Code); ;
                         console.log('RequestId-->' + result.CommonMsg.RequestId);
                  }
           }
    });

    You can view the details about the SDK common result objects here.

  3. If there are any error messages, check the network connection between the client and the OBS server first. If the connection is good, provide the error messages to the OBS client O&M team for locating the cause.
  4. If an ObsClient API call fails, obtain the HTTP status code and OBS server-side error code from the SDK common result objects, and compare them to locate the cause.
  5. If the cause cannot be found in step 4, obtain the request ID returned by the OBS server from the SDK common result objects and contact the OBS server O&M team to locate the cause.
  6. If the request ID cannot be obtained from the SDK common result objects, contact the OBS client O&M team to locate the failure cause.