Performing a Streaming Download

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

Sample code:

String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";

// Create an instance of ObsClient.
final ObsClient obsClient = new ObsClient(ak, sk, endPoint);

ObsObject obsObject = obsClient.getObject("bucketname", "objectname");

// Obtain the object content.
Log.i("GetObject", "Object content:");
InputStream input = obsObject.getObjectContent();
byte[] b = new byte[1024];
ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
int len;
while ((len=input.read(b)) != -1){
       bos.write(b, 0, len);
}
 
Log.i("GetObject", new String(bos.toByteArray()));
bos.close();
input.close();
  • After ObsClient.getObject is called, an instance of ObsObject will be returned. This instance contains the residing bucket, name, properties, and input streams of the object.
  • You can perform operations on the input streams of an object to read and write the object contents to a local file or to the memory.

Object input streams obtained by ObsObject.getObjectContent must be closed explicitly. Otherwise, resource leakage occurs.