gram-js / gramjs

NodeJS/Browser MTProto API Telegram client library,
MIT License
1.3k stars 178 forks source link

How to get user's profile picture #459

Open Ali559 opened 1 year ago

Ali559 commented 1 year ago

So I've been trying to find a way to get a user's profile picture and send it to my frontend app in view it in basic html, I've noticed that the data comes as a buffer and I cannot decode it.

so what I'm asking is simple: How do I get the URL for a user's profile picture?

painor commented 1 year ago

you can't get a URL of a picture but you can download it and probably convert it to base64 to show it in your html. https://gram.js.org/beta/classes/TelegramClient.html#downloadProfilePhoto

Ali559 commented 1 year ago

Hey @painor thanks for the quick reply, I appreciate it.

ak4zh commented 1 year ago

@painor When utilizing web.telegram.org, the profile pictures are presented as HTTP images. Given that web.telegram.org can acquire a public URL, I believe that gramjs should also have the capability to do so.

Here's an example of a gramjs profile picture: <img src="blob:https://web.telegram.org/249ccf3b-4646-4ba7-a08f-80ac85c146f2" alt="" class="" style="width: 581px;" draggable="true">

painor commented 1 year ago

They simply host it in their server. They download it as a blob (buffer) and then they can do whatever they want with it.

Gramjs does not have a server to upload things to nor does telegram provide any.