FILEREF_UPGRADE_NEEDED using GetFile function of TLSharp

148 Views Asked by At

I'm trying to dowload a file from a conversation in telegram. I`m using TLSharp lib...

Please check my code:

      var result = await client.GetContactsAsync();

                var user = result.Users
                    .OfType<TLUser>()
                    .FirstOrDefault(x => x.Phone  == "<phoneNumber>");

                var inputPeer = new TLInputPeerUser() { UserId = user.Id };
                var res = await client.SendRequestAsync<TLMessages>(new TLRequestGetHistory() { Peer = inputPeer });
                var document = res.Messages
                    .OfType<TLMessage>()
                    .Where(m => m.Media != null)
                    .Select(m => m.Media)
                    .OfType<TLMessageMediaDocument>()
                    .Select(md => md.Document)
                    .OfType<TLDocument>()
                    .First();

                var resFile = await client.GetFile(
                    new TLInputDocumentFileLocation()
                    {
                        AccessHash = document.AccessHash,
                        Id = document.Id,
                        Version = document.Version
                    },

(int)Math.Pow(2, Math.Ceiling(Math.Log(document.Size, 2))) * 4);

This code is getting this exception:

FILEREF_UPGRADE_NEEDED

Please, there are any way to get a file from an conversation without get this error?

1

There are 1 best solutions below

0
On

TLSharp seems no longer maintained. You might want to switch to WTelegramClient which is similar but better.

Then you can use the helper method that simplify the download process:

using (var stream = File.Create(outputFilename))
   await client.DownloadFileAsync(document, stream);