6
votes

I am trying to create folders using google drive API using the scope 'https://www.googleapis.com/auth/drive.file'

Surprisingly, the api allows me to upload multiple files with the exact same title into the same folder. I can even see these duplicate files if I browse over to my google drive in my web browser.

Is there any way I can have the API prevent duplicates in filenames? I could check for a file's existence before uploading another with the same name, but that seems to be a strange way to handle writing to a file system...

2
have you dealt with your question? I am facing on same issue..Ben Luk
starting to think the development of the drive api was outsourced by google :D the queries are also fun ...Jan Schmutz

2 Answers

8
votes

"Is there any way I can have the API prevent duplicates in filenames?"

No. In Drive, files are uniquely identified by their ID. Attributes such as name (aka Title), parent directories, permissions, description, are simply attributes. It works rather well.

Remember that Drive is all about synchronisation between devices, eg. your pc, your Android phone, your Chromebook, etc. How would Drive keep track of which file was which if it identified them by name, which will often get renamed. Eg. I have a file called "Foo" on Drive, synced to my Android phone, and I rename that file to "Bar". If title was the identifier, my Android phone would see that as a new file. Because ID is the (immutable) identifier, and title is merely an attribute, Android can update the title attribute without getting confused.

0
votes

With this 3rd party SDK you can specifically set whether a file should be overwritten or it will cause an exception.

void upload(String filePath, InputStream stream, long size, boolean overwrite); 

Links to SDK and Documentation