A
A
alegzz2021-04-11 19:04:52
Python
alegzz, 2021-04-11 19:04:52

AIOGRAM - how to send an album with content from variables?

I use requests to download video files and want to send them via the tg bot. the aiogram documentation has an example of how to send local files, but I have the contents of the file in requests.get.content - how can I send them without writing to a file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2021-04-12
@alegzz

When dealing with a function that wants a file object, you can use io.StringIO or io.BytesIO.
For example:

media.attach_photo(io.BytesIO(requests.get('http://foo/bar.jpg').content), 'Foo Bar')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question