Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if file exists in Google Drive (and not trashed) using Java?

Pretty self-explanatory title. I'm using Google Drive Client Api for Java. What I currently have is as follows:

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

However, I can't find the property in File used to check if a file is trashed or not. File.getExplicitlyTrashed() gives me null for both trashed and not trashed files.

like image 869
woojoo666 Avatar asked Oct 20 '22 04:10

woojoo666


1 Answers

The trashed property is hidden inside the File.Labels class, which you can get from File.getLabels(). A working example is:

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;
}
like image 186
woojoo666 Avatar answered Oct 22 '22 16:10

woojoo666