You can configure one or more conditions for downloads. If the specified conditions are met, the object can be downloaded. If the specified conditions are not met, an error code is returned and the object cannot be downloaded.

You can configure the following conditions:

Parameter Description
If-Modified-Since If the specified time is earlier than the time the object is modified, the object can be downloaded. Otherwise, an error (304 Not modified) is returned.
If-Unmodified-Since If the specified time is later than or equal to the time the object is modified, the object can be downloaded. Otherwise, an error (412 Precondition failed) is returned.
If-Match If the specified ETag matches that of an object, the object can be downloaded. Otherwise, an error (412 Precondition failed) is returned.
If-None-Match If the specified ETag does not match that of an object, the object can be downloaded. Otherwise, an error (304 Not modified) is returned.

Run the following code for conditional download:

public void testGetObjectWithHeaders() throws Exception {
        GetObjectRequest request = new GetObjectRequest(bucketName, objectName);
        request.setRequestHeaders(...) ;


        OSSAsyncTask task = oss.asyncGetObject(request, getCallback);
        task.waitUntilFinished();

        GetObjectRequest rq = getCallback.request;
        GetObjectResult result = getCallback.result;

    }