• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Android SDK)
  4. Object Upload
  5. Performing a Streaming Upload

Performing a Streaming Upload

Streaming upload uses InputStream as the data source of an object. You can call ObsClient.putObject to upload the data streams to OBS. Sample code is as follows:

Uploading a Character String (Byte Array)

String endPoint = "yourdomainname";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);

String content = "Hello OBS";
obsClient.putObject("bucketname", "objectkey", new ByteArrayInputStream(content.getBytes()));

// Close obsClient.
obsClient.close();

Uploading a Network Stream

String endPoint = "yourdomainname";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);

InputStream inputStream = new URL("http://www.a.com").openStream();
obsClient.putObject("bucketname", "objectkey", inputStream);

// Close obsClient.
obsClient.close();

Uploading a File Stream

String endPoint = "yourdomainname";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);

FileInputStream fis = new FileInputStream(new File("localfile"));
obsClient.putObject("bucketname", "objectkey", fis);

// Close obsClient.
obsClient.close();