mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 02:43:45 +03:00
Fix file name could be lost when uploading files
Leading to invalid extension when sending photos.
This commit is contained in:
parent
eb67ef1b15
commit
fda6840449
|
@ -90,6 +90,7 @@ def _resize_photo_if_needed(
|
||||||
buffer = io.BytesIO()
|
buffer = io.BytesIO()
|
||||||
result.save(buffer, 'JPEG', progressive=True, **kwargs)
|
result.save(buffer, 'JPEG', progressive=True, **kwargs)
|
||||||
buffer.seek(0)
|
buffer.seek(0)
|
||||||
|
buffer.name = getattr(file, 'name', None)
|
||||||
return buffer
|
return buffer
|
||||||
except IOError:
|
except IOError:
|
||||||
return file
|
return file
|
||||||
|
|
|
@ -348,21 +348,22 @@ class _FileStream(io.IOBase):
|
||||||
self._size = os.path.getsize(self._file)
|
self._size = os.path.getsize(self._file)
|
||||||
self._stream = open(self._file, 'rb')
|
self._stream = open(self._file, 'rb')
|
||||||
self._close_stream = True
|
self._close_stream = True
|
||||||
|
return self
|
||||||
|
|
||||||
elif isinstance(self._file, bytes):
|
if isinstance(self._file, bytes):
|
||||||
self._size = len(self._file)
|
self._size = len(self._file)
|
||||||
self._stream = io.BytesIO(self._file)
|
self._stream = io.BytesIO(self._file)
|
||||||
self._close_stream = True
|
self._close_stream = True
|
||||||
|
return self
|
||||||
|
|
||||||
elif not callable(getattr(self._file, 'read', None)):
|
if not callable(getattr(self._file, 'read', None)):
|
||||||
raise TypeError('file description should have a `read` method')
|
raise TypeError('file description should have a `read` method')
|
||||||
|
|
||||||
elif self._size is not None:
|
self._name = getattr(self._file, 'name', None)
|
||||||
self._name = getattr(self._file, 'name', None)
|
self._stream = self._file
|
||||||
self._stream = self._file
|
self._close_stream = False
|
||||||
self._close_stream = False
|
|
||||||
|
|
||||||
else:
|
if self._size is None:
|
||||||
if callable(getattr(self._file, 'seekable', None)):
|
if callable(getattr(self._file, 'seekable', None)):
|
||||||
seekable = await _maybe_await(self._file.seekable())
|
seekable = await _maybe_await(self._file.seekable())
|
||||||
else:
|
else:
|
||||||
|
@ -373,8 +374,6 @@ class _FileStream(io.IOBase):
|
||||||
await _maybe_await(self._file.seek(0, os.SEEK_END))
|
await _maybe_await(self._file.seek(0, os.SEEK_END))
|
||||||
self._size = await _maybe_await(self._file.tell())
|
self._size = await _maybe_await(self._file.tell())
|
||||||
await _maybe_await(self._file.seek(pos, os.SEEK_SET))
|
await _maybe_await(self._file.seek(pos, os.SEEK_SET))
|
||||||
self._stream = self._file
|
|
||||||
self._close_stream = False
|
|
||||||
else:
|
else:
|
||||||
_log.warning(
|
_log.warning(
|
||||||
'Could not determine file size beforehand so the entire '
|
'Could not determine file size beforehand so the entire '
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
# Versions should comply with PEP440.
|
# Versions should comply with PEP440.
|
||||||
# This line is parsed in setup.py:
|
# This line is parsed in setup.py:
|
||||||
__version__ = '1.31.0'
|
__version__ = '1.31.1'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user