0

有错误:LIMIT_INVALID

内存异常?有人做过例子吗?

TLMessageMediaDocument mediaFile = _msg.Media as TLMessageMediaDocument;
TLDocument doc = mediaFile.Document as TLDocument;
client.GetFile(new TLInputDocumentFileLocation() {
   AccessHash = doc.AccessHash,
   Id = doc.Id, Version = doc.Version },
doc.Size).Wait();
4

1 回答 1

1

下载文件时,有几个步骤是必须知道的。电报文档说:

1. If precise flag is not specified, then
    The parameter offset must be divisible by 4 KB.
    The parameter limit must be divisible by 4 KB.
    1048576 (1 MB) must be divisible by limit.

2. If precise is specified, then
    The parameter offset must be divisible by 1 KB.
    The parameter limit must be divisible by 1 KB.
    limit must not exceed 1048576 (1 MB).

我不知道什么是精确的,这就是为什么我使用第一个(使用可被 4 KB 整除的限制和偏移量),因为 4 可被 1 整除。

这是文档链接:https ://core.telegram.org/api/files

这是我使用 C# TLSharp 的代码

var mb = 1048576;
var upperLimit = (int)Math.Pow(2, Math.Ceiling(Math.Log(fileInfo.Size, 2))) * 4;
var limit = Math.Min(mb, upperLimit);

var currentOffset = 0;
using (var fs = File.OpenWrite(filename))
{
    while (currentOffset < fileInfo.Size)
    {
        file = m_telegramClient.GetFile(fileLocation, limit, currentOffset).ConfigureAwait(false).GetAwaiter().GetResult();
        fs.Write(file.Bytes, 0, file.Bytes.Length);
        currentOffset += file.Bytes.Length;
    }

    fs.Close();
}
于 2020-09-05T17:37:20.880 回答