Actually i try to uplaod file on my telegramChannel, but it take too much time (1:00 to 1:30 minutes) as compare of my server speed .
Testing from Microsoft Azure (...)…
Retrieving speedtest.net server list…
Selecting best server based on ping…
Hosted by Airfiber Networks Pvt Ltd (Chennai) [21.06 km]: 2.242 ms
Testing download speed……………………………………………………………………..
Download: 894.45 Mbit/s
Testing upload speed…………………………………………………………………………………………
Upload: 931.89 Mbit/s
but when i try to uplaod same file on through me laptop or my phone then it is very fast upload, while file size is just 50MB .
const { TelegramClient } = require('telegram');
const { StringSession } = require('telegram/sessions');
const fs = require('fs');
require('dotenv').config({
path: './.env'
});
const apiId = parseInt(process.env.API_ID);
const apiHash = process.env.API_HASH;
const stringSession = new StringSession(process.env.SESSION); // fill this later with the value from session.save()
const channelUsername = 'testchanned';
const file_name = 'dream11_1.apk';
(async () => {
const client = new TelegramClient(stringSession, apiId, apiHash, { connectionRetries: 5 });
await client.start();
const getChannelId = async () => {
try {
const channel = await client.getEntity(channelUsername);
return channel.id;
} catch (error) {
console.error('Failed to get channel ID:', error);
throw error; // Rethrow the error to handle it in the calling function
}
};
const uploadFile = async (channelId) => {
try {
const result = await client.sendFile(channelId, {
file: file_name,
caption: ``${file_name}``,
});
console.log('File uploaded successfully:', result);
} catch (error) {
console.error('Error uploading file:', error);
throw error; // Rethrow the error to handle it in the calling function
}
};
try {
const channelId = await getChannelId();
await uploadFile(channelId);
// fs.unlinkSync(file_name); // Consider using fs.unlink to asynchronously delete the file
console.log('File uploaded and deleted successfully');
} catch (error) {
console.error('An error occurred:', error);
}
})();
I try to upload file on channel fast because , i try find this issue why it takes time too much while file size is little and my server speed is too good and i also my telegram premium account. But still same issue. can anyody help me how to iprove this code for fast uploading.