• Object Storage Service

  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Java SDK)
  4. Quick Start
  5. General Examples of ObsClient

General Examples of ObsClient

When you call an API in an instance of ObsClient, if no exception is thrown, the return value is valid and an instance of the HeaderResponse class (or of its sub-class) is returned. If any exception is thrown, obtain the error information from the instance of ObsException.

Sample code:

ObsClient obsClient = null; 
    String endPoint = "yourdomainname";
    String ak = "*** Provide your Access Key ***";
    String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
    obsClient = new ObsClient(ak, sk, endPoint);
// Call APIs to perform related operations, for example, uploading an object.
    HeaderResponse response = obsClient.putObject("bucketname", "objectkey", new File("localfile"));
catch (ObsException e)
    System.out.println("Response Code: " + e.getResponseCode());
    System.out.println("Error Message: " + e.getErrorMessage());
    System.out.println("Error Code:" + e.getErrorCode());
    System.out.println("Request ID:" + e.getErrorRequestId());
    System.out.println("Host ID:" + e.getErrorHostId());
 // Close obsClient.
    if(obsClient != null){
        catch (IOException e)