Upload File From Colab to Google Drive Folder

随声附和 提交于 2020-01-24 21:29:07

问题


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

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