【问题标题】:Google Drive API write a new drive file thats a not a Drive 'viewer' typeGoogle Drive API 编写一个新的驱动器文件,它不是驱动器“查看器”类型
【发布时间】:2013-04-13 03:34:19
【问题描述】:

我开始使用 GooG Drive API。我已经成功完成了 quickstart.py 教程/示例。都很好。

显示在我的云端硬盘中的文件以云端硬盘“查看器”文件的形式打开,而不是我需要的可编辑文件。我猜它是 MIMEtype,但该文档是一个 .txt 文件,所以我不确定它应该设置为什么。那么我如何将它写为 Drive 可编辑文件类型???

谢谢

Dav-o

media_body = MediaFileUpload(FILENAME, mimetype='text/plain', resumable=True)
body = {
  'title': 'My document',
  'description': 'A test document',
  'mimeType': 'text/plain'
}

file = drive_service.files().insert(body=body, media_body=media_body).execute()
pprint.pprint(file)

【问题讨论】:

    标签: python file-upload google-drive-api google-docs-api


    【解决方案1】:

    您正在以 txt 格式上传文件,这是任何 Google 编辑器都无法编辑的格式。

    您应该将文件转换为相应的原生 Google 格式,以便在云端硬盘默认查看器中对其进行编辑:

    https://developers.google.com/drive/v2/reference/files/insert

    要在上传期间启用转换,您必须在插入请求中设置convert=True

    file = drive_service.files().insert(body=body, media_body=media_body, convert=True).execute()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      • 2015-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多