You can call the HeadObject operation to obtain only the metadata but not the content of an object.

Sample code

The following code provides an example on how to obtain object metadata:

// Create a request to synchronously obtain the metadata of an object. 
// Specify the bucket name such as examplebucket and the full path of the object such as exampledir/exampleobject.txt. The full path cannot contain the bucket name. 
HeadObjectRequest head = new HeadObjectRequest("examplebucket", "exampledir/exampleobject.txt");

// Obtain the metadata of the object. 
OSSAsyncTask task = oss.asyncHeadObject(head, new OSSCompletedCallback<HeadObjectRequest, HeadObjectResult>() {
    @Override
    public void onSuccess(HeadObjectRequest request, HeadObjectResult result) {
    
    // Obtain the length of the object. 
        Log.d("headObject", "object Size: " + result.getMetadata().getContentLength()); 
    // Obtain the type of the object. 
        Log.d("headObject", "object Content Type: " + result.getMetadata().getContentType()); 
    }

    @Override
    public void onFailure(HeadObjectRequest request, ClientException clientExcepion, ServiceException serviceException) {
        // Handle request exceptions. 
        if (clientExcepion != null) {
            // Handle client exceptions, such as network exceptions. 
            clientExcepion.printStackTrace();
        }
        if (serviceException != null) {
            // Handle service exceptions. 
            Log.e("ErrorCode", serviceException.getErrorCode());
            Log.e("RequestId", serviceException.getRequestId());
            Log.e("HostId", serviceException.getHostId());
            Log.e("RawMessage", serviceException.getRawMessage());
        }
    }
});

// task.waitUntilFinished(); // Wait until the metadata of the object is obtained. 

References

For more information about the API operation that you can call to obtain object metadata, see GetObjectMeta.