Skip to content

Sending images from bytes. #119

Description

@Highstaker

Sending images from existing files works fine. But if I want to send it from bytes stored in variable, there is no way to do it. Bytes are not JSON-serializable in Python3.

I tried
>>> f=io.BufferedReader(BytesIO(b))
>>> bot.sendPhoto(chat_id=chat_id,photo=f)
where b contains image file contents as bytes (downloaded from internet, for example). decoding it doesn't work.
But it says

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/telegram/bot.py", line 126, in decorator
    result = func(self, *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/telegram/bot.py", line 158, in decorator
    result = request.post(url, data)
  File "/usr/local/lib/python3.4/dist-packages/telegram/utils/request.py", line 95, in post
    data = InputFile(data)
  File "/usr/local/lib/python3.4/dist-packages/telegram/inputfile.py", line 76, in __init__
    self.filename = os.path.basename(self.input_file.name)
AttributeError: '_io.BytesIO' object has no attribute 'name'

Guess the code requires a filename.

Can the sending from bytes function be made?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Fields

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions