All Products
Search
Document Center

Object Storage Service:Restore objects by using OSS SDK for Android

Last Updated:Feb 20, 2024

Archive, Cold Archive, and Deep Cold Archive objects must be restored before they can be read. This topic describes how to restore Archive, Cold Archive, and Deep Cold Archive objects.

Usage notes

  • Before you run the sample code in this topic, you must create an OSSClient instance by using methods such as using a custom domain name or Security Token Service (STS). For more information, see Initialization.

Examples

The following sample code provides an example on how to restore an object named exampleobject.txt in a bucket named examplebucket. The storage class of the exampleobject.txt object is Archive, Cold Archive, or Deep Cold Archive.

Note

If you successfully restore an object by using the following sample code, HTTP status code 202 is returned. In this case, a period of time is required to restore the object. For more information, see RestoreObject.

// Restore the object. 
RestoreObjectRequest restore = new RestoreObjectRequest();
// Specify the name of the bucket. Example: examplebucket. 
restore.setBucketName("examplebucket");
// Specify the full path of the object. Do not include the bucket name in the full path. Example: exampleobject.txt. 
restore.setObjectKey("exampleobject.txt");
OSSAsyncTask task = oss.asyncRestoreObject(restore, new OSSCompletedCallback<RestoreObjectRequest,
        RestoreObjectResult>() {
    @Override
    public void onSuccess(RestoreObjectRequest request, RestoreObjectResult result) {
        Log.i("info", "code::"+result.getStatusCode());

    }

    @Override
    public void onFailure(RestoreObjectRequest request, ClientException clientException,
                          ServiceException serviceException) {
        Log.e("errorMessage", "error: "+serviceException.getRawMessage());

    }
});

task.waitUntilFinished();

References

  • For the complete sample code that is used to restore Archive, Cold Archive, and Deep Cold Archive objects, visit GitHub.

  • For more information about the API operation that you can call to restore Archive, Cold Archive, and Deep Cold Archive objects, see RestoreObject.

  • For more information about how to initialize an OSSClient instance, see Initialization.