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

Can any one tell me how to download media from message object. #212

Open rajuss2018 opened 2 years ago

rajuss2018 commented 2 years ago

Describe the bug Media object is as below: "media": { "": "messageMediaPhoto", "flags": 1, "photo": { "": "photo", "flags": 0, "has_stickers": false, "id": "6262407075049091160", "access_hash": "10817854802644809094", "filereference": { "0": 2, "1": 86, "2": 161, "3": 148, "4": 170, "5": 0, "6": 0, "7": 0, "8": 238, "9": 97, "10": 94, "11": 134, "12": 172, "13": 91, "14": 115, "15": 107, "16": 86, "17": 116, "18": 35, "19": 195, "20": 117, "21": 93, "22": 219, "23": 16, "24": 163, "25": 140, "26": 60, "27": 18, "28": 152 }, "date": 1633493147, "sizes": [ { "": "photoStrippedSize", "type": "i", "bytes": { "0": 1, "1": 17, "2": 40, "3": 209, "4": 242, "5": 151, "6": 208, "7": 81, "8": 229, "9": 46, "10": 15, "11": 2, "12": 157, "13": 199, "14": 173, "15": 40, "16": 232, "17": 121, "18": 169, "19": 229, "20": 93, "21": 135, "22": 118, "23": 53, "24": 97, "25": 83, "26": 212, "27": 3, "28": 78, "29": 242, "30": 83, "31": 63, "32": 118, "33": 156, "34": 157, "35": 233, "36": 127, "37": 138, "38": 142, "39": 85, "40": 216, "41": 46, "42": 200, "43": 218, "44": 20, "45": 199, "46": 11, "47": 205, "48": 21, "49": 35, "50": 125, "51": 218, "52": 40, "53": 229, "54": 93, "55": 130, "56": 236, "57": 138, "58": 148, "59": 116, "60": 52, "61": 81, "62": 84, "63": 33, "64": 209, "65": 119, "66": 167, "67": 255, "68": 0, "69": 24, "70": 162, "71": 138, "72": 0, "73": 71, "74": 251, "75": 180, "76": 81, "77": 69, "78": 0, "79": 127 } }, { "": "photoSize", "type": "m", "location": { "": "fileLocationToBeDeprecated", "volume_id": "500178700279", "localid": 84068 }, "w": 320, "h": 140, "size": 17077 }, { "": "photoSize", "type": "x", "location": { "_": "fileLocationToBeDeprecated", "volume_id": "500178700279", "local_id": 84069 }, "w": 626, "h": 273, "size": 51910 } ], "dc_id": 5 } }

I tried upload.getFile API as below:

const file = await mtproto .call('upload.getFile', { location: { _: 'inputPhotoFileLocation', id: media.photo.id, access_hash: media.photo.access_hash, file_reference: media.photo.file_reference, thumb_size: 'y', }, })

joeberetta commented 2 years ago

@rajuss2018 inside the sizes array bytes field has actual file bytes as I know, just save it properly