gramjs icon indicating copy to clipboard operation
gramjs copied to clipboard

Best approach for uploading videos?

Open happymaskterriblefate opened this issue 2 years ago • 6 comments

Hi there,

I'm wondering the best way to upload an mp4 video using gramjs. Right now I can successfully upload a video via:

sendFile(client, entity, { file });

where the entity is a Channel instance and the file is a filepath to the video on my hard drive. However, when the video appears in the channel, it has no thumbnail, and it says the length of the video is 0:00:00.

If I drag and drop the same file through the telegram desktop app, the thumbnail appears and the video length is correct. Are there extra steps or a different approach I need to take when uploading a video using gramjs?

Thank you in advance, and thank you for the great module!

happymaskterriblefate avatar Sep 09 '21 02:09 happymaskterriblefate

for files under 10mb you'll need to set those attributes yourself. For thumbnail there is a thumbnail property that you can use.

For video length/heigh/width as well you can set those attributes in the attributes field. Telegram desktop does this when you start uploading client side.

painor avatar Sep 09 '21 11:09 painor

Thank you -- I'll give it a shot and see if I can get it working. Will followup.

happymaskterriblefate avatar Sep 09 '21 11:09 happymaskterriblefate

good luck. it will look something like this

    client.sendFile(entity,{
        file,
        thumb:"path to thumb",
        attributes:[new Api.DocumentAttributeVideo({
            duration:duration,
            h:height,
            w:width,
        })]
    })

painor avatar Sep 09 '21 11:09 painor

@painor That worked! Thank you so much. Is there a place in the docs where I can send a PR to add the solution to the recipe?

happymaskterriblefate avatar Sep 09 '21 12:09 happymaskterriblefate

@painor That worked! Thank you so much. Is there a place in the docs where I can send a PR to add the solution to the recipe?

you can add an example to the doc string of sendFile (in this repo) and they will be updated here https://gram.js.org/beta/classes/client_telegramclient.telegramclient.html#sendfile

painor avatar Sep 09 '21 12:09 painor

I have a image ArrayBuffer. can i use it as thumbnail. how to do it. i tried like this

` const toUpload = new CustomFile("video.mp4", video.byteLength, "", video as any); const thumbTopUpload = new CustomFile("img.jpg", thumbBuffer.byteLength, "", thumbBuffer as any);

callback('Uploading Video')
const file = await client.uploadFile({
    file: toUpload,
    workers: 3,
    onProgress: (e) => {
        console.log(e);

        callback(e)
    }
});

callback('Uploading thumbnail')

const thumb = await client.uploadFile({
    file: thumbTopUpload,
    workers: 3,
    onProgress: (e) => {
        console.log(e);

        callback(e)
    }
});

console.log(thumb);


client.sendFile(channel, { file, caption: msg, thumb: thumb}).then((res) => console.log(res)).catch((res) => console.log(res))`

But it says error like Error: Could not create file from [object Object] if i did send file without thumb like this client.sendFile(channel, { file, caption: msg, thumb: thumb}).then((res) => console.log(res)).catch((res) => console.log(res)) then it is working well. How to fix it

adhil72 avatar Jun 25 '23 06:06 adhil72