简体   繁体   中英

how to upload to folder and replace files using python and Google Drive?

I crafted this little script which helps me upload files from terminal to Google Drive. I am going to use it with cron to make my life easier a bit. This is the script I have: https://github.com/goranpejovic/drive-uploader/blob/master/upload.py

It essentially uploads file to GDrive and optionally converts it to Google Docs format. Now, I want to implement two more things but I am not sure how.

First is I want to have ability to upload to folders remotely. Not just create folder locally and upload it (this would be nice too now when I think of it), but upload file to remote folder in Google Drive. Is this possible? If so, any suggestion?

Second, I would like to be able to replace files that already exist on Drive. Obviously same filename doesn't matter to GDrive so I am assuming it has to do with metadata I am passing as "body". Or some other ways?

Thank you!

To create folders in drive is similar than creating a file, the difference would be the mime type: "application/vnd.google-apps.folder". So instead of uploading a folder, you have to use file.insert to create a new one in Drive.

Creating or inserting a file in Drive, as you mentioned, it will create a new file, even if the name already exists. In order to replace a file, you will have to update the existing file with the new information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM