Skip to content

miniproto.file_id.encode_file_id

encode_file_id(media: Media | object) -> str

Encode supported Telegram media or input locations into a local file ID.

Fields are serialized as supplied. Decoding applies integer-range and size limits, so invalid source fields can produce an ID that decode_file_id rejects. Encoding makes no Telegram request and does not renew file references.

Parameters:

  • media (Media | object) – A Media value, supported generated media object or input file location.

Returns:

  • str – Canonical URL-safe mpf1_ identifier containing the reusable location fields.

Raises:

  • TypeError – If the location shape is unsupported or an extracted field is not JSON-serializable.
  • ValueError – If JSON serialization rejects an extracted value.