【发布时间】:2018-02-16 16:38:12
【问题描述】:
我正在尝试通过 v3 API 将文件 (pdf) 上传到 Google Drive,我想从电子邮件的附件中创建文件。我发现的所有文档似乎都依赖于我想上传 Blob 的本地文件。
到目前为止,这是我的代码的精髓:
class MailHandler(InboundMailHandler):
def receive(self, mail_message):
logging.info("Received a message from: " + mail_message.sender)
if hasattr(mail_message, 'attachments'):
logging.info("Has attachments")
for filename, filecontents in mail_message.attachments:
file_blob = filecontents.payload.decode(filecontents.encoding)
credentials = UserModel.query().get()
media = MediaFileUpload(filename, mimetype = 'image/jpg')
file = drive.files().create( body = {'name': 'testupload.jpg'}, media_body = media)
file.execute(c.credentials.authorize(http))
这会引发错误,因为文件不存在,而不是因为它是 blob。
有人可以帮帮我吗?
【问题讨论】: