Performing a Conditioned 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
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 |
- 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 = "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);
GetObjectRequest request = new GetObjectRequest("bucketname", "objectname");
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();
Last Article: Obtaining Download Progresses
Next Article: Rewriting Response Headers
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.