diff --git a/telethon/client/uploads.py b/telethon/client/uploads.py index a5eed2a4..aed9b136 100644 --- a/telethon/client/uploads.py +++ b/telethon/client/uploads.py @@ -39,10 +39,11 @@ def _resize_photo_if_needed( or (isinstance(file, io.IOBase) and not file.seekable())): return file - before = file.tell() if isinstance(file, io.IOBase) else 0 if isinstance(file, bytes): file = io.BytesIO(file) + before = file.tell() if isinstance(file, io.IOBase) else None + try: # Don't use a `with` block for `image`, or `file` would be closed. # See https://github.com/LonamiWebs/Telethon/issues/1121 for more.