mtproto-core icon indicating copy to clipboard operation
mtproto-core copied to clipboard

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

Open exilibriss opened this issue 3 years ago • 1 comments

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 avatar Sep 13 '21 03:09 exilibriss

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, // 

Hope this solution helps someone.

exilibriss avatar Sep 15 '21 04:09 exilibriss