Reputation: 493
I have an Android app that uploads to a folder within Google Drive. I have that part working OK. Now if I delete the folder within Google Drive and then my app attempts to upload to this folder, the upload is "successful" but I cannot find the file in Google Drive.
I would expect an Exception to be thrown by Google Drive but as far as I can tell, it is not. Is this by design? Do I need to resort to checking if the folder exists before each upload or is there another way?
Thanks
Here is the code that I am using
File body = new File();
body.setTitle(title);
body.setDescription(description);
body.setMimeType(mimeType);
// Set the parent folder.
body.setParents(Arrays.asList(new ParentReference().setId(parentId)));
// File's content.
java.io.File fileContent = new java.io.File(filename);
FileContent mediaContent = new FileContent(mimeType, fileContent);
try {
drive.files().insert(body, mediaContent).execute();
} catch (IOException e) {
e.printStackTrace();
}
Upvotes: 2
Views: 420
Reputation: 15014
The return value of the file insert method is the metadata of the inserted file. You can use that to know everything about the new file on Google Drive, including the folder(s) it is included in.
Upvotes: 2