【发布时间】:2020-03-16 13:44:59
【问题描述】:
我正在使用来自 David Lloyd 响应的 Upload File to Google-drive Teamdrive folder with PyDrive 中的此代码,但在运行他的代码后,我无法将 mimeType 更改为 image/jpg。我试过像这样添加我的代码:
parent_folder_id = 'YYYY'
f = drive.CreateFile({
'title': 'image.jpg', 'mimeType': 'image/jpg'
'parents': [{
'kind': 'drive#fileLink',
'teamDriveId': team_drive_id,
'id': parent_folder_id
}]
})
f.SetContentString("path/image.jpg")
f.Upload(param={'supportsTeamDrives': True})
# where XXXX and YYYY are the team drive and target folder ids found from the end of the URLS when you open them in your browser.
但图片在 Google 云端硬盘中以 PDF 文件的形式上传。
【问题讨论】:
-
你有没有考虑过使用谷歌提供的Python官方Drive API Client?
-
我尝试使用,但无法使用官方使其工作(我是 GoogleApi 和编程的新手,所以要在通过 PyDrive 学习的 API 中编码,因为我发现在其中编码更容易)。但令我感到沮丧的是,这种 mimetype 在上传到我的云端硬盘时有效,但在共享文件夹中无效。
-
我已将 mimeType 更改为 image/jpeg。它在谷歌驱动器中显示为图像,但它没有给我预览,当我下载它时说文件已损坏。任何想法可能是造成这种情况的原因吗?
标签: python google-drive-api jpeg mime-types