Warm tip: This article is reproduced from serverfault.com, please click

其他-Python:如何使用folderId将文件上传到Google云端硬盘中的特定文件夹

(其他 - Python: How to upload files to a specific folder in Google Drive using folderId)

发布于 2014-11-06 15:40:49

因此,我正在尝试将文件上传到用户指定的特定Google云端硬盘文件夹中。以下是我尝试过的代码。我得到了folderID,并尝试将文件发布到该文件夹​​中,但是出现404 Not Found错误。

def post_file(self, files_to_send, config = {}):
  if config:
    if type(config) is str:
      config = literal_eval(config)
    path_id = config.get('path')
  for file_to_send in files_to_send:
    filename = file_to_send.name.split('/')[-1]
    status = self.call.post('https://www.googleapis.com/upload/drive/v2/files?uploadType=media/' + str(path_id) + "/children")

使用Drive API文档上的界面,我可以获取具有相同folderID的数据,但无法发布(即使使用界面)。Files_to_send是包含所有我需要上传到特定文件夹的文件的列表,并且config包含文件夹路径。

我需要帮助来了解我在做什么错。我已经阅读了文档并查看了其他答案,但没有找到解决方案。当我不指定文件夹ID时,虚拟文件​​确实会发布到驱动器上,但不会上传我想要的文件,并且当我指定FolderID时它也不会上传任何内容。

本质上,我需要帮助将文件插入Google云端硬盘中的特定文件夹。

谢谢!

Questioner
AlvinJ
Viewed
0
Omri Segal 2014-11-06 23:49:28

我相信你应该发送包含字段的元数据JSON parents就像是:

{
    "parents" : [path_id]
}

你可以在以下位置尝试使用此API:https//developers.google.com/drive/v2/reference/files/insert