mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-11-04 01:47:27 +03:00 
			
		
		
		
	Fix upload_file not seeking streams back
This would cause issues in _cache_media since utils.is_image fails in the second pass (it respects the stream's position, and the user may rightfully pass a stream that should be read only from one pos).
This commit is contained in:
		
							parent
							
								
									fcfebf75a3
								
							
						
					
					
						commit
						758556cd30
					
				| 
						 | 
				
			
			@ -384,7 +384,17 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
 | 
			
		|||
        elif isinstance(file, bytes):
 | 
			
		||||
            file_size = len(file)
 | 
			
		||||
        else:
 | 
			
		||||
            file = file.read()
 | 
			
		||||
            if isinstance(file, io.IOBase) and file.seekable():
 | 
			
		||||
                pos = file.tell()
 | 
			
		||||
            else:
 | 
			
		||||
                pos = None
 | 
			
		||||
 | 
			
		||||
            # TODO Don't load the entire file in memory always
 | 
			
		||||
            data = file.read()
 | 
			
		||||
            if pos is not None:
 | 
			
		||||
                file.seek(pos)
 | 
			
		||||
 | 
			
		||||
            file = data
 | 
			
		||||
            file_size = len(file)
 | 
			
		||||
 | 
			
		||||
        # File will now either be a string or bytes
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user