gpt4 book ai didi

java - Google Drive REST Api 通过其 fileId 下载文件

转载 作者:行者123 更新时间:2023-11-30 10:08:40 25 4
gpt4 key购买 nike

大家好,我遇到了一个问题。在我的应用程序中,我存储了用户之前在 GoogleDrive 文件选择器中选择的文件的 fileId。我还在设备中存储该文件的本地副本。每次启动后我想刷新本地文件,所以我想从驱动器下载它们。但我不清楚,我应该怎么做。
我看到了this documentation , 但我不明白从哪里获得 driveService, 在此代码中使用

driveService.files().get(fileId)
.executeMediaAndDownloadTo(outputStream);

我不知道这段代码中的driveService是什么。 (哪个类实例)以及如何获取它
请帮助我,谢谢。

附言
抱歉我的英语不好

最佳答案

您应该查看 resumable Media Downloads 下的文档它可能会给您一些线索。

class CustomProgressListener implements MediaHttpDownloaderProgressListener {
public void progressChanged(MediaHttpDownloader downloader) {
switch (downloader.getDownloadState()) {
case MEDIA_IN_PROGRESS:
System.out.println(downloader.getProgress());
break;
case MEDIA_COMPLETE:
System.out.println("Download is complete!");
}
}
}

OutputStream out = new FileOutputStream("/tmp/driveFile.jpg");

DriveFiles.Get request = drive.files().get(fileId);
request.getMediaHttpDownloader().setProgressListener(new CustomProgressListener());
request.executeMediaAndDownloadTo(out);

关于java - Google Drive REST Api 通过其 fileId 下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53668431/

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