我正在尝试将.xlsx 文件上传到 Google 驱动器。我可以上传它。但是当我们尝试在云端硬盘中打开相同的文件时,必须使用 Google 表格打开它。因此,它会创建一个具有相同名称的新文件并占用驱动器空间。
我想我需要在上传时更改 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'
在 Google 文件
我找到了另一个MimeType
'mimeType':'application/vnd.google-apps.spreadsheet'
但它给了我错误
ApiRequestError
:https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable&alt=json 返回“提供的 mime 类型无效”>
请建议我如何才能达到理想的效果。
1 回答
我认为主要的问题是 pydrive 会使用谷歌驱动器 v2 还是谷歌驱动器 v3。我在源接缝中挖掘指向 v2,这意味着在创建文件时需要为上传时要转换的文件发送
convert=true
files.inesrt通过在文件上传时发送转换,它将自动转换为谷歌文档类型。