[英]How do I copy a file on a Google Drive using v3 of the Google Drive Java API?
[英]How do I export a Google Drive file using the Java SDK
经过一些尝试和错误后,我得到了这段代码:
String odt = file.getExportLinks().get("application/pdf");
try (FileOutputStream fos = new FileOutputStream("C:/data/test_" + file.getTitle() + ".pdf")) {
service.files().get(file.getId()).getMediaHttpDownloader().download(new GenericUrl(odt), fos);
} catch (IOException ioe) {
ioe.printStackTrace();
}
这里有两种选择:
public static InputStream download(Drive service, String url) throws IOException {
return service.getRequestFactory().buildGetRequest(new GenericUrl(url)).execute().getContent();
}
public static void download(Drive service, String url, OutputStream os) throws IOException {
HttpRequestFactory rf = service.getRequestFactory();
new MediaHttpDownloader(rf.getTransport(), rf.getInitializer()).download(new GenericUrl(url), os);
}
但我确实想知道是否有更惯用的方法来获取 MediaHttpDownloader。
PS:我认为应该在Google文档页面中添加正确的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.