Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting multiple parents for Google Drive File

Read several SO posts (ex. here) that allude to Google Drive files being able to have multiple parents, i.e. same file in multiple folders. I wanted to test this out, as I am brainstorming ideas for backing up collections of files for my android app, without having to reload the entire collection on each backup.

Unfortunately, when i set the file metadata as such below, the file does not upload to either parent-folder. It does upload and appear when I comment out one of the parents.

As a result, I assume that the ability to set multiple parents is reserved for special folders like "trash" or "favorites?" Or do i need to try updating the file after initial creation?

    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;
}
like image 203
NameSpace Avatar asked Feb 14 '23 17:02

NameSpace


1 Answers

** May 2020 - See comment below. Google has decided to disallow multiple parents from September 2020 onward. This renders both the question and the answer stale**

As a result, I assume that the ability to set multiple parents is reserved for special folders like "trash" or "favorites?"

No. Any file can have multiple parents. You can try it easily at https://developers.google.com/drive/v2/reference/files/insert#try-it

Or do i need to try updating the file after initial creation?

No. You can have multiple parents on creation.

It's a good idea to get into the habit of looking at the http requests that your app is sending and compare it with what you see at https://developers.google.com/drive/v2/reference/files/insert#try-it

You can enable http logging here https://developers.google.com/drive/v2/reference/files/insert#try-it

like image 143
pinoyyid Avatar answered Mar 04 '23 06:03

pinoyyid