Reputation: 3
I want use google drive in my android app to backup folders that contain text, image and video files.
My problem is that while I can upload each text, image and video file separately using the Drive API, I can't see a way to upload entire folders at once so that the organisation remains intact.
The organisation of the folders is as follows:
app>Projects>notes>photos/text/video
Ideally I would like to upload the folder "app" and along with all of its contents while keeping the parent/child structure.
Upvotes: 0
Views: 225
Reputation: 490
Are you using Google Drive Api for Android or the REST Api ?
If you are using the REST API you can create a folder like this :
private String createFolder() throws IOException {
File fileMetadata = new File();
fileMetadata.setName("FOLDER_NAME");
fileMetadata.setMimeType("application/vnd.google-apps.folder");
File file = mService.files().create(fileMetadata)
.setFields("id")
.execute();
String Folderid = file.getId();
And then with the file id you do this :
File nFile= new File();
nFile.setName("FILE_NAME");
nFile.setParents(Collections.singletonList(Folderid));
File file = mService.nFile().create(fileMetadata).execute();
The setParents is used to create the file INSIDE the parent which is the folder just created in this example.
Upvotes: 1