如何从存储应用程序数据中删除文件 - Google Drive API

时间:2015-07-28 10:24:46

标签: google-drive-api

  

Google Drive API包含一个特殊的隐藏文件夹,可用于您的应用   可用于存储应用程序特定数据。

这是教程:Storing Application Data

我使用此方法将文件插入隐藏文件夹:

    private static File insertFileInApplicationDataFolder(Drive service, String title, String description,
        String mimeType, String filename) {
    // File's metadata.
    File body = new File();
    body.setTitle(title);
    body.setDescription(description);
    body.setMimeType(mimeType);
    body.setParents(Arrays.asList(new ParentReference().setId("appfolder")));

    // File's content.
    java.io.File fileContent = new java.io.File(filename);
    FileContent mediaContent = new FileContent(mimeType, fileContent);
    try {
        File file = service.files().insert(body, mediaContent).execute();
        return file;
    } catch (IOException e) {
        System.out.println("An error occured: " + e);
        return null;
    }
}

现在,我想删除文件夹中的所有文件。

我尝试使用service.files().get("appfolder").execute().clear();,但它不起作用。文件仍然存在。

1 个答案:

答案 0 :(得分:0)

您发布的链接指的是Android API(GDAA),但您的代码使用的是REST API。确保你了解其中的差异。

“appfolder”只是文件夹的别名。您可以像任何常规文件夹一样使用它,例如。您可以列出其子项并将其删除。

出于好奇,您正在调用的“clear()”方法是什么?我从来没有见过记录。