【发布时间】:2018-12-12 08:40:55
【问题描述】:
我正在尝试将 .xlsx 文件上传到谷歌驱动器。我可以上传它。 但是当我们尝试在 Drive 中打开同一个文件时,它必须使用 Google Sheets 打开。因此,它会创建一个同名的新文件并占用 Drive 空间。
我想我需要在上传时更改 MimeType。
我试过的是:
file = drive.CreateFile({"parents": [{"kind": "drive#fileLink", "id": FolderID}]
,'title': fileName
,'mimeType':'application/vnd.ms-excel'})
file.SetContentFile('12dec2018.xlsx')
file.Upload()
我也试过这个
'mimeType':'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
我找到了另一个MimeType
'mimeType':'application/vnd.google-apps.spreadsheet'
但它给了我错误
ApiRequestError: https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable&alt=json 返回“提供的 MIME 类型无效”>
请建议我怎样才能达到理想的结果。
【问题讨论】:
-
通过 Drive REST API(不是 PyDrive)这是一个非常简单的任务:developers.google.com/drive/api/v3/… PyDrive 可能需要您使用特定的标志或类似的指示符,您希望上传并转换为 G套件文件。
-
感谢编辑。
标签: python google-api google-sheets-api pydrive