GramJS

upload.GetFile

Returns content of a whole file or its part.

Example

const { Api, TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result = await client.invoke(
    new Api.upload.GetFile({
      location: new Api.InputFileLocation({
        volumeId: BigInt("-4156887774564"),
        localId: 43,
        secret: BigInt("-4156887774564"),
        fileReference: Buffer.from("arbitrary data here"),
      }),
      offset: BigInt("-4156887774564"),
      limit: 100,
      precise: true,
      cdnSupported: true,
    })
  );
  console.log(result); // prints the result
})();
import { Api, TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result: Api.upload.File = await client.invoke(
    new Api.upload.GetFile({
      location: new Api.InputFileLocation({
        volumeId: BigInt("-4156887774564"),
        localId: 43,
        secret: BigInt("-4156887774564"),
        fileReference: Buffer.from("arbitrary data here"),
      }),
      offset: BigInt("-4156887774564"),
      limit: 100,
      precise: true,
      cdnSupported: true,
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
flags#Flags, see TL conditional fields
preciseflags.0?trueDisable some checks on limit and offset values, useful for example to stream videos by keyframes
cdnSupportedflags.1?trueWhether the current client supports CDN downloads
locationInputFileLocationFile location
offsetintNumber of bytes to be skipped
limitintNumber of bytes to be returned

Result

upload.File

Possible errors

CodeTypeDescription
400CHANNEL_INVALIDThe provided channel is invalid.
400CHANNEL_PRIVATEYou haven't joined this channel/supergroup.
400FILE_REFERENCE_*The file reference expired, it must be refreshed.
406FILEREF_UPGRADE_NEEDEDThe client has to be updated in order to support file references.
400FILE_ID_INVALIDThe provided file id is invalid.
400FILE_REFERENCE_EXPIREDFile reference expired, it must be refetched as described in the documentation.
400LIMIT_INVALIDThe provided limit is invalid.
400LOCATION_INVALIDThe provided location is invalid.
400MSG_ID_INVALIDInvalid message ID provided.
400OFFSET_INVALIDThe provided offset is invalid.
400PEER_ID_INVALIDThe provided peer id is invalid.

Can bots use this method?

Yes

Encrypted CDNs for Speed and Security

How to handle file references.

File references

How to handle file references.