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...
"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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With