Google Drive API doesn't return error when uploading files to non-existent parent directory

I’m working on an Android application that saves files to a specific directory in Google Drive using the API. The basic upload functionality works fine when the target directory exists.

However, I discovered something strange. When the parent directory gets removed from Google Drive and my app tries to upload a file to that deleted directory, the API call completes without any errors. The upload appears successful, but the uploaded file is nowhere to be found in Google Drive.

I expected the Google Drive API to throw some kind of error or exception when trying to upload to a non-existent parent folder, but that doesn’t seem to happen. Is this the intended behavior of the API?

Should I manually verify that the parent directory still exists before every file upload, or is there a better approach to handle this situation?

Here’s my current upload implementation:

File documentMetadata = new File();
documentMetadata.setTitle(documentName);
documentMetadata.setDescription(documentDesc);
documentMetadata.setMimeType(fileType);

// Specify the parent directory
documentMetadata.setParents(Arrays.asList(new ParentReference().setId(folderId)));

// Prepare file content
java.io.File localFile = new java.io.File(filePath);
FileContent content = new FileContent(fileType, localFile);

try {
    driveService.files().insert(documentMetadata, content).execute();
} catch (IOException ex) {
    ex.printStackTrace();
}

this drove me nuts when i first ran into it! google drive api does this weird thing where it quietly dumps orphaned files into the root folder instead of just failing. super annoying. what i do now is wrap the upload in try-catch, then immediately search the expected parent folder to make sure the file actually ended up where it should.

Yeah, that’s exactly how Google Drive API works - super counterintuitive though. When you upload to a deleted parent folder, it just ignores the bad reference and dumps the file in root instead. No error, nothing. The upload actually succeeds, just not where you expected. I hit this same problem building a document management system last year. Fixed it by adding a quick validation step before uploads. I just call driveService.files().get(folderId).execute() and catch any 404 errors to check if the parent folder still exists. Takes almost no time but stops the silent failures. You could also refresh your folder references regularly, especially if you’re caching folder IDs for a while. Users can delete Drive folders outside your app, so keeping those references current is smart anyway.

Same issue hit me in production six months back. Google Drive API does this by design - when you give it a bad parent reference, it just dumps the file in root without telling you. Super annoying for error handling. I fixed it by caching folder modification times and re-checking if parent folders exist when enough time’s passed for changes. Also started tagging uploaded files with metadata so I could find and move anything that landed in the wrong spot. Pre-upload validation works too, but it’ll slow you down on bulk uploads.