google drive API allows duplicates?

别等时光非礼了梦想. 提交于 2019-12-08 19:37:57

问题


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...


回答1:


"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.




回答2:


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



来源:https://stackoverflow.com/questions/28215076/google-drive-api-allows-duplicates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!