Uploading files

Using SendFile

Uploading files can be tricky since GramJS needs to support both browsers and nodeJS. You can use the sendFile methods for most use cases

await client.sendFile("me",{
    file: "video.mp4",
});

Using UploadFile

If you need more control over the upload process you can use uploadFile which returns an InputFile that you can add attributes to and use in other methods such as changing profile picture.

when using uploadFile you'll need to specify the size and name yourself using the CustomFile class

const toUpload = new CustomFile("photo.jpg", fs.statSync("../photo.jpg").size, "../photo.jpg");
const file = await client.uploadFile({
   file: toUpload,
   workers: 1,
 });
await client.invoke(new Api.photos.UploadProfilePhoto({
    file: file,
}));

Increasing speed

If you want to upload at a faster rate GramJS provides an attribute called workers. by default, it's 1 which means a stable and slow upload. increasing this will improve upload speed but might make it unstable.

Note: Using anything above 15 is discouraged because telegram will disconnect you.

const toUpload = new CustomFile("bigFile.zip", fs.statSync("../bigFile.zip").size, "../bigFile.zip");
const file = await client.uploadFile({
   file: toUpload,
   workers: 10,
 });

Last updated