Answer the question
In order to leave comments, you need to log in
How to send a photo from Telegram to Google Drive?
The telegram bot downloads the document to the server, and then sends the document to Google drive.
How can I upload a document to Google Drive without saving it to the server?
I use pyTelegramBotAPI and Google Drive API.
try:
file_info = bot.get_file(message.document.file_id)
src = path + message.document.file_name
downloaded_file = bot.download_file(file_info.file_path)
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
file_metadata = {
'name': message.document.file_name,
'parents': [folder_id]
}
media = MediaFileUpload(src, mimetype=message.document.mime_type)
service.files().create(
body=file_metadata,
media_body=media,
fields='id'
).execute()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question