K
K
ki ki2020-11-14 23:48:06
Google
ki ki, 2020-11-14 23:48:06

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

1 answer(s)
L
Lesha, 2020-11-15
@hydrugz

How can I upload a document to Google Drive without saving it to the server?

How to mount google drive in linux?
or
Upload to Google Drive by URL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question