alik0211 / mtproto-core

Telegram API JS (MTProto) client library for Node.js and browser
https://mtproto-core.js.org
GNU General Public License v3.0
630 stars 113 forks source link

API.call upload.getFile w/ constructor inputPhotoFileLocation return nothing #209

Open exilibriss opened 2 years ago

exilibriss commented 2 years ago

Dudes, i have a problem:

@mtproto/core v6.0.1
node v14.17.4

When i use method upload.getFile with constructor inputPhotoFileLocation, call return nothing w/o exception or error and cpu load about 100% for pending promise.

const photo_response = await api.call('upload.getFile', params);

e.g. params of method call:

{
  location: {
    _: 'inputPhotoFileLocation',
    id: 'photo_id_from_photo_object',
    access_hash: 'access_hash_from_photo_object',
    file_reference: new Binary(Buffer.from("some_binary_code_here", "hex"), 0),
    thumb_size: 'y'
  },
  offset: 0,
  limit: photo_size
}

Can u help me w/ download photo by using new API constructor - inputPhotoFileLocation ?

exilibriss commented 2 years ago

Solution:

  1. U need recompile bytes string from file_reference represent for request (it's not working w/o Buffer - wrong bytes represent)
  2. U need setting up limit = 1024* 1024 (this is max value, any values not working, even despite the limits from the API documentation, idk why)
    let buf = message.media.photo.file_reference;
    Buffer.from(buf.toString('hex'), 'hex')

{ location: { _: 'inputPhotoFileLocation', id: 'photo_id_from_photo_object', access_hash: 'access_hash_from_photo_object', file_reference: buf, // <-- recompiled buffer here thumb_size: 'y' }, offset: 0, limit: 1024 * 1024 // <-- maximum value for limit }

Hope this solution helps someone.