Reputation: 63
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.
Upvotes: 2
Views: 816
Reputation: 22306
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
.
Upvotes: 3