• Object Storage Service

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

Performing a Conditioned Download

When downloading an object, you can specify one or more conditions. Only when the conditions are met, the object will be downloaded. Otherwise, an exception will be thrown and the download will fail.

You can set the following conditions:

Parameter

Description

Method in OBS Android SDK

If-Modified-Since

Returns the object if it is modified after the time specified by this parameter; otherwise, an exception is thrown.

GetObjectRequest.setIfModifiedSince

If-Unmodified-Since

Returns the object if it remains unchanged since the time specified by this parameter; otherwise, an exception is thrown.

GetObjectRequest.setIfUnmodifiedSince

If-Match

Returns the source object if its ETag is the same as the one specified by this parameter; otherwise, an exception is thrown.

GetObjectRequest.setIfMatchTag

If-None-Match

Returns the source object if its ETag is different from the one specified by this parameter; otherwise, an exception is thrown.

GetObjectRequest.setIfNoneMatchTag

NOTE:
  • The ETag of an object is the MD5 check value of the object.
  • If a request includes If-Unmodified-Since or If-Match and the specified condition is not met, 412 Precondition Failed will be returned.
  • If a request includes If-Modified-Since or If-None-Match, and the specified condition is not met, 304 Not Modified will be returned.

Sample code:

String endPoint = "yourdomainname";
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);

GetObjectRequest request = new GetObjectRequest("bucketname", "objectkey");
request.setRangeStart(0l);
request.setRangeEnd(1000l);

request.setIfModifiedSince(new SimpleDateFormat("yyyy-MM-dd").parse("2016-01-01"));
ObsObject obsObject = obsClient.getObject(request);

obsObject.getObjectContent().close();

// Close obsClient.
obsClient.close();