File name missing in Telegram bot API response for image uploads

I’m working with a Telegram bot and noticed something strange with file uploads. When users send document files like PDFs or text files, the API response includes the original filename in the response data. But when they upload images, the filename is completely missing from the response.

Document upload response (works fine):

{
  "update_id": 987654321,
  "message": {
    "message_id": 25,
    "from": {
      "id": 1234567890,
      "is_bot": false,
      "first_name": "John",
      "username": "john_doe"
    },
    "document": {
      "file_name": "report.txt",
      "mime_type": "text/plain",
      "file_id": "BQACAgUAAxkBAAMoZvIvTyoUOQUwqs8JkQlUWyADDCMAArsQAAJklpFX9DE7pYrYYYk2BA",
      "file_size": 45000
    }
  }
}

Image upload response (filename missing):

{
  "update_id": 987654322,
  "message": {
    "message_id": 26,
    "from": {
      "id": 1234567890,
      "is_bot": false,
      "first_name": "John",
      "username": "john_doe"
    },
    "photo": [
      {
        "file_id": "AgACAgUAAxkBAAMpZvI4PMcy02obaSa47F9dsjKuleIAAmvBMRtklpFX",
        "width": 320,
        "height": 240,
        "file_size": 15000
      }
    ]
  }
}

How can I get the original image filename from the Telegram API response? I need it for proper file processing.

Yeah, you can’t get around this - it’s a core limitation of Telegram’s Bot API. They strip filenames from photos because Telegram treats images differently than documents. It creates multiple resolutions and compresses them, so they’re optimized media instead of raw files. I ran into this exact problem building a file management bot last year. My workaround was using the caption field. Just have users put the filename in the image caption, then extract it with code. Takes some user training but works great once they’re used to it.

Yeah, this is how Telegram works by design. When you send images as photos, the API compresses them and strips the filename - you just get different size variants instead. I’ve run into this building bots too. Here’s what works: Either tell users to send images as documents (not photos) in your help text, or set up a two-step flow where they send the filename first, then the image. Your bot can link them together using message order or sessions.

yea, i get that frustration! it’s annoying how telegram treats pics differently. ur best bet is to tell users to just send their images as files instead of photos if they wanna keep the original filenames. hope that helps!