How to determine if a file exists in Google Drive (and not corrupted) using Java?

Pretty clear name. I am using Google Drive Client Api for Java. I currently have the following:

File f = mService.files.get(fileId).execute();

However, I cannot find the property in File, used to check if the file was damaged or not. File.getExplicitlyTrashed()gives me a null value for both truncated and non-truncated files.

+4
source share
1 answer

The property is trashedhidden inside a class File.Labelsthat you can get from File.getLabels(). Working example:

public boolean validFileId(String id) {
    try {
        File f = mService.files().get(id).execute();
        return !f.getLabels().getTrashed();
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println("bad id: " + id);
    }
    return false;
}
+3
source

All Articles