为Google云端硬盘文件设置多个父级

Nam*_*ace 3 android google-drive-api

阅读几个SO帖子(例如此处),提示Google Drive文件可以包含多个父文件,即多个文件夹中的相同文件.我想测试一下,因为我正在集思广益,为我的Android应用程序备份文件集合,而不必在每个备份上重新加载整个集合.

不幸的是,当我在下面设置文件元数据时,该文件不会上传到任一父文件夹.当我评论其中一位父母时,它会上传并显示.

因此,我认为设置多个父项的功能是为"垃圾"或"收藏夹"等特殊文件夹保留的.或者我是否需要在初始创建后尝试更新文件?

    List<ParentReference> parents = new ArrayList<ParentReference>();
    parents.add(new ParentReference().setId(parentId1));
    parents.add(new ParentReference().setId(parentId2));


static private File create_File(String fileName, List<ParentReference> parents){

    String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension("db");

    System.out.println("Mimetype " + mimeType);

    // File's metadata.
    File file = new File();
    file.setMimeType(mimeType);
    file.setTitle(fileName);
    file.setParents(parents);

    return file;
}
Run Code Online (Sandbox Code Playgroud)

pin*_*yid 7

因此,我认为设置多个父项的功能是为"垃圾"或"收藏夹"等特殊文件夹保留的.

不.任何文件都可以包含多个父项.您可以在https://developers.google.com/drive/v2/reference/files/insert#try-it轻松试用.

或者我是否需要在初始创建后尝试更新文件?

不.您可以在创作时拥有多个父母.

最好养成查看应用发送的http请求的习惯,并将其与您在https://developers.google.com/drive/v2/reference/files/insert#try-上看到的内容进行比较.

您可以在此处启用http记录https://developers.google.com/drive/v2/reference/files/insert#try-it