sochix / TLSharp

Telegram client library implemented in C#
1.01k stars 380 forks source link

infinity session when get photo with client.GetFile #861

Open emreordukaya opened 5 years ago

emreordukaya commented 5 years ago

Hi I try to get photo from telegram to file. So first, I record all areas to database as below; Size: 153570
LocalId: 222091 Secret: 3036022842088152691 VolumId: 455226032

Size: 83721 LocalId: 312637 Secret: -98427489733507458 VolumId: 446330158

I can normally save these above photos to the file with this code.

foreach (var tf in model) { //get profile pic int filePart = 256 * 1024; int offset = 0; TLFile resFile; Image img; using (MemoryStream ms = new MemoryStream()) { while (offset < tf.Size) { resFile = await client.GetFile(new TLInputFileLocation() { LocalId = (int)tf.LocalId, Secret = (long)tf.Secret, VolumeId = (long)tf.VolumId }, filePart, offset); ms.Write(resFile.Bytes, 0, resFile.Bytes.Length); offset += filePart; } img = Image.FromStream(ms); img.Save(Path.Combine(HttpRuntime.AppDomainAppPath, "Content/images/TLimages/messages/" + tf.Messages.MessageURL), System.Drawing.Imaging.ImageFormat.Jpeg); Thread.Sleep(1000); } }

But I cant save some photos like belows; Size: 61908 LocalId: 359212 Secret: 5202940104763596803 VolumId: 853507450

I debugged this photo and saw that project go infinity session like this; first; 1

Then 2

After that program go again first step and go infinity session. 1