问题
I want to upload a file from colab to a specific folder in my google drive. I can get the folder by using the folder id and below snippet:
my_folder = drive.ListFile(
{'q': "'1QYaM1vaUvdzbdsfWbsolncz1xc2pgnpextuP' in parents"}).GetList()
But my question: how do I upload a file(image) to this folder? Is there a function such as
my_folder.upload(my_file)?
So far I have seen some examples with zip files but I do not want to upload it as a zip file.
回答1:
I take from this answer
fid = '1QYaM1vaUvdzbdsfWbsolncz1xc2pgnpextuP'
f = drive.CreateFile({"parents": [{"kind": "drive#fileLink", "id": fid}]})
f.SetContentFile( some_path )
f.Upload()
来源:https://stackoverflow.com/questions/50647677/upload-file-from-colab-to-google-drive-folder