• Object Storage Service

  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Android SDK)
  4. Quick Start
  5. General Examples for the OBS Server

General Examples for the OBS Server

When you call an API related to the ObsClient class, if no exception is thrown, the return value is valid and an instance of the HeaderResponse class or of its sub-class are returned. If any exception is thrown, obtain the error information from an 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"));
    Log.i("PutObject", response);
catch (ObsException e)
    Log.e("PutObject", "Response Code: " + e.getResponseCode());
    Log.e("PutObject", "Error Message: " + e.getErrorMessage());
    Log.e("PutObject", "Error Code:       " + e.getErrorCode());
    Log.e("PutObject", "Request ID:      " + e.getErrorRequestId());
    Log.e("PutObject", "Host ID:           " + e.getErrorHostId());
// Close obsClient.
    if(obsClient != null){
        catch (IOException e)