Chaitu Reddy February 2016

Google drive getMimeType returning only null values

I am trying to download files from drive using version 3 of Google Drive api in java. I now need the MimeType of files to identify their content type. when I tried calling

File.getMimeType

i am getting null value.

 Drive service=getDriveService();

 FileList result = service.files().list()    
          .setPageSize(100)
           .setFields("nextPageToken, files(id, name)")
             .execute();


 List<File> files = result.getFiles();
     if (files == null || files.size() == 0) {
         System.out.println("No files found.");
     }
     else {
         System.out.println("Files:");
            for (File file : files) {
                System.out.printf("%s (%s)(%s)\n", file.getName(),file.getId(),file.getMimeType());
            }
      }

I tried calling other methods like getFullFileExtension but they all are returning null values.

Could anyone please tell me where i did mistake? And how to solve this get the mimetype and other values.

Answers


pinoyyid February 2016

I haven't played much with v3 yet, but from your code you do

setFields("nextPageToken, files(id, name)")

and then

file.getMimeType()

Since you only asked for the id and name to be fetched, it shouldn't be too surprising that mimeType is null. Try adding mimeType to the fields in setFields.

Post Status

Asked in February 2016
Viewed 1,964 times
Voted 8
Answered 1 times

Search




Leave an answer