I have a simple function to download images from Telegram messages by using Pyrogram, but the download_media
method doesn’t download anything for me, and the returned file_path is always None. The received message
object and its photo
attribute do have some data in them, but still, the download won’t work for me. I tried passing message
, m_photo
and file_id
to download_media
to no avail.
async def download_photo(message):
m_photo = message.photo
file_id = m_photo.file_id
file_unique_id = m_photo.file_unique_id
width = m_photo.width
height = m_photo.height
file_size = m_photo.file_size
date = m_photo.date
print(m_photo)
print(f"Photo details - File ID: {file_id}, File Unique ID: {file_unique_id}, Width: {width}, Height: {height}, File Size: {file_size}, Date: {date}")
file_path = await app.download_media(m_photo, file_name=f'{message.chat.id}_{file_unique_id}.jpg')
return file_path
asyncio.run(download_photo(message))
2
Answers
Is your pyrogram client in the group or channel from where you want to download? If this is not the case, I think you should try it that way, something that would resolve the conflict is to try with filters
download_media() often has FloodWait exception hidden by pyrogram library.
You could