gpt4 book ai didi

java - 使用 String[] args 参数作为 .setQ 参数中的变量 (Google Drive API V3)

转载 作者:行者123 更新时间:2023-12-01 19:18:52 25 4
gpt4 key购买 nike

我尝试使用 API 从 Google 云端硬盘下载 .bin 和 .xml 文件,因此我在 String[] args 中创建了一个定义 MIME 类型的参数。

该方法需要在.setQ中指定mimetype,所以我想知道是否可以将mimeType设置为定义其是.bin还是.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);
}
}

最佳答案

  • 您想要使用 Drive API v3 中的 files.list 方法检索特定文件夹中 mimeType 为 .bin.xml 的文件。
    • .bin.xml 文件的 mimeType 为 application/x-binary(application 或 text)分别为/xml
  • 您希望使用搜索查询来实现此目的。

如果我的理解是正确的,这个答案怎么样?请将此视为几个可能答案之一。

示例搜索查询 1:

用于检索特定文件夹中的 application/x-binaryapplication/xmltext/xml 文件的搜索查询googledrivefolderid 可以按如下方式创建。

'googledrivefolderid' in parents and (mimeType = 'application/x-binary' or mimeType = 'application/xml' or mimeType = 'text/xml')
  • 如果文件的mimeType不同,您可以使用Drive API中的Files: get方法进行检查。您可以在 here 进行测试。测试时,请输入文件ID,然后点击“EXECUTE”按钮。

引用文献:

如果我误解了您的问题并且这不是您想要的方向,我深表歉意。

关于java - 使用 String[] args 参数作为 .setQ 参数中的变量 (Google Drive API V3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59384800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com