1
我正在尝试使用python api从Google Drive下载一些图片文件。 我正在使用的代码首先获取文件资源对象,找到downloadUrl并使用它下载文件。问题是gif和png文件似乎没有下载url。从Google Drive下载图片
service = self.user.profile.DriveService()
conditions = []
conditions.append("title='image.png')
conditions.append("trashed = false")
response = service.files().list(q=" and ".join(conditions)).execute()
f = response['items'][0]
url = f['downloadUrl']
# Now download the file from url
...
这适用于下载文本和html文件。 当我尝试下载图像文件时,它们具有downloadUrl属性。 下面是一个例子图像文件资源
u'alternateLink': u'https://docs.google.com/document/d/1S9amlqcwLl9FOYmHFhv_RK_NwPI47IWj8iGcIK9p8hk/edit',
u'appDataContents': False,
u'createdDate': u'2013-01-20T08:39:55.314Z',
u'editable': True,
u'embedLink': u'https://docs.google.com/document/d/1S9amlqcwLl9FOYmHFhv_RK_NwPI47IWj8iGcIK9p8hk/preview',
u'etag': u'"Q0cVodxX8sh4vfxZTlOyWcmmc0k/MTM1ODY3MTE5NzY5Nw"',
u'exportLinks': {u'application/pdf': u'https://docs.google.com/feeds/download/documents/export/Export? id=1S9amlqcwLl9FOYmHFhv_RK_NwPI47IWj8iGcIK9p8hk&exportFormat=pdf',
u'application/rtf': u'https://docs.google.com/feeds/download/documents/export/Export?id=1S9amlqcwLl9FOYmHFhv_RK_NwPI47IWj8iGcIK9p8hk&exportFormat=rtf',
u'application/vnd.oasis.opendocument.text': u'https://docs.google.com/feeds/download/documents/export/Export?id=1S9amlqcwLl9FOYmHFhv_RK_NwPI47IWj8iGcIK9p8hk&exportFormat=odt',
u'application/vnd.openxmlformats-officedocument.wordprocessingml.document': u'https://docs.google.com/feeds/download/documents/export/Export?id=1S9amlqcwLl9FOYmHFhv_RK_NwPI47IWj8iGcIK9p8hk&exportFormat=docx',
u'text/html': u'https://docs.google.com/feeds/download/documents/export/Export?id=1S9amlqcwLl9FOYmHFhv_RK_NwPI47IWj8iGcIK9p8hk&exportFormat=html',
u'text/plain': u'https://docs.google.com/feeds/download/documents/export/Export?id=1S9amlqcwLl9FOYmHFhv_RK_NwPI47IWj8iGcIK9p8hk&exportFormat=txt'},
u'iconLink': u'https://ssl.gstatic.com/docs/doclist/images/icon_11_document_list.png',
u'id': u'1S9amlqcwLl9FOYmHFhv_RK_NwPI47IWj8iGcIK9p8hk',
u'kind': u'drive#file',
u'labels': {...},
u'lastModifyingUserName': u'Max Ferguson',
u'lastViewedByMeDate': u'2013-01-20T08:39:57.697Z',
u'mimeType': u'application/vnd.google-apps.document',
u'modifiedByMeDate': u'2013-01-20T08:39:57.697Z',
u'modifiedDate': u'2013-01-20T08:39:57.697Z',
u'ownerNames': [u'Max Ferguson'],
u'parents': [{u'id': u'0BxiZtRrps_bKaXM1OXJtUXBkOTg',
u'isRoot': False,
u'kind': u'drive#parentReference',
u'parentLink': u'https://www.googleapis.com/drive/v2/files/0BxiZtRrps_bKaXM1OXJtUXBkOTg',
u'selfLink': u'https://www.googleapis.com/drive/v2/files/1S9amlqcwLl9FOYmHFhv_RK_NwPI47IWj8iGcIK9p8hk/parents/0BxiZtRrps_bKaXM1OXJtUXBkOTg'}],
我不明白为什么没有downloadUrl。这可能是因为mimetype是application/vnd.google-apps.document,但该文件绝对是一个图像。缩略图链接等指向图像。任何帮助,将不胜感激。
在谷歌原生格式(应用/ vnd.google-apps.XXX)
当您上传图片时是否启用了转换功能?作为application/vnd.google-apps.document的mimetype会让我相信它已被转换。 – David
是的,我确实启用了转换,并且我上传的文件已转换。当我禁用转换时,所有新图像文件都有我请求的downloadUrl。谢谢。 –