【问题标题】:How can I download files from team drives?如何从团队驱动器下载文件?
【发布时间】:2019-10-28 20:56:19
【问题描述】:

我想定期从 Google 云端硬盘上的共享团队云端硬盘下载和上传文件。我可以上传到文件夹,但不能下载。

这是我尝试过的

team_drive_id = 'YYY'
file_to_download= 'ZZZ'
parent_folder_id = 'XXX'

f = drive.CreateFile({
        'id':file_to_download,
        'parents': [{
        'kind': 'drive#fileLink',
        'teamDriveId': team_folder_id,
        'id': parent_drive_id
    }]
})
f= drive.CreateFile({'id': file_to_download})
f.GetContentFile('test.csv', mimetype='text/csv')

但这就是我得到的:

ApiRequestError: <HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/file_to_download?alt=json returned "File not found: file_to_download">

有什么建议吗?

【问题讨论】:

  • 您确定路径test.csv的文件正确且文件存在。因为这就是错误所说的
  • 我的路径错了,感谢@UliSotschok的帮助

标签: python pydrive


【解决方案1】:

按照可以看到的文档here

首先创建文件:

f = drive.CreateFile({'id': file_to_download})

然后你在文件上设置内容

f.SetContentString("whatever comes inside this file, it is a csv so you know what to expect to be here")

并完成您需要做的上传

f.Upload()

之后,文件在此处正确创建,您可以使用GetContentString 方法读取它

【讨论】:

  • 这仅在您在同一会话中创建和下载文件时有效。如果我稍后尝试返回,它无法找到该文件,或者如果我使用新生成的 ID 创建另一个 CreateFile 实例,它会返回一个 404 文件未找到。
猜你喜欢
  • 2019-12-31
  • 2018-06-25
  • 2018-11-14
  • 1970-01-01
  • 1970-01-01
  • 2018-11-01
  • 1970-01-01
  • 2019-10-16
  • 1970-01-01
相关资源
最近更新 更多