I'm trying to download .bin and .xml files from Google Drive using the API, so I created a parameter in the String[] args that defines the mime type.
The method requires specifying the mimetype in the .setQ, so I'm wondering if mimeType can be set to the parameter that defines whether its .bin or .xml.
private static void downloadFile(Drive service, String src_dir, String dst_dir, String mime_type) {
try {
FileList result = service.files().list()
//application/x-binary for bin files; (application or text)/xml for xml files
.setQ("'googledrivefolderid' in parents " + "and (mimeType = mime_type)")
.setFields("nextPageToken, files(id, name)")
.execute();
List<File> files = result.getFiles();
if (files == null || files.isEmpty()) {
System.out.println("No files found.");
} else {
//System.out.println("Files:");
for (File file : files) {
String fileId = file.getId();
String fileName = file.getName();
OutputStream outputstream = new FileOutputStream(dst_dir + fileName);
service.files().get(fileId)
.executeMediaAndDownloadTo(outputstream);
outputstream.flush();
outputstream.close();
}
}
} catch (IOException e) {
System.out.println("An error occurred: " + e);
}
}
.bin
or .xml
in the specific folder using files.list method in Drive API v3.
.bin
or .xml
are application/x-binary
and (application or text)/xml
, respectively.If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
The search query for retrieving the files of application/x-binary
or application/xml
or text/xml
in the specific folder of googledrivefolderid
can be created as follows.
'googledrivefolderid' in parents and (mimeType = 'application/x-binary' or mimeType = 'application/xml' or mimeType = 'text/xml')
If I misunderstood your question and this was not the direction you want, I apologize.