0

How do I send a photo to chat without compression, as a file. When I implement it with the current method, the file is sent as a document without an extension.

bot = TeleBot("API")

@bot.message_handler(content_types=['text'])
def send(message):
    with open("5.jpg", "rb") as file:
        f = file.read()
    bot.send_document(message.chat.id, document=f)

bot.polling(True)
Risinell
  • 1
  • 2

1 Answers1

2

When you do

f = file.read()

Combined with document=f, Telegram will receive the content of the file.


To send the file with the original filenamem, pass the file variable from open():

with open("/tmp/ccatt.jpeg", "rb") as file:
    bot.send_document(123456789, document=file)

enter image description here

0stone0
  • 34,288
  • 4
  • 39
  • 64
  • Glad it helped! Consider reading [what should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers). Accepting/Upvoting any answers that might have helped give both you and the answerer some rep and shows to the rest of the community that the answer has been usefull. – 0stone0 Jun 02 '22 at 15:01