According to Telegram documentation:
Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail’s width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can only be uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
The problem is that I am fetching the thumbnail from flac music using the jaudiotagger
library. It returns a bufferedImage, which I then use to write it to a file. But before I write it, I resize it to a valid size using the function:
fun BufferedImage.resize(targetWidth: Int, targetHeight: Int): BufferedImage {
val resizedImage = BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB)
val graphics2D: Graphics2D = resizedImage.createGraphics()
graphics2D.drawImage(this, 0, 0, targetWidth, targetHeight, null)
graphics2D.dispose()
return resizedImage
}
After that, I write to a jpeg format file: ImageIO.write(thumbnail.image.resize(320, 320), "jpeg", thumbnailImage)
Then, using the tgbotapi library, I send the audio:
bot.sendAudio(
chatId = ChatId(RawChatId(ID)),
audio = usableSong.asMultipartFile(),
title = title,
performer = if (title.contains(artist)) null else artist,
duration = audio.audioHeader.trackLength.toLong(),
disableNotification = true,
protectContent = false,
thumb = thumbnailImage.asMultipartFile()
)
But still, thumbnail does not appear in the message, although the audio itself comes in. (Yes, thumbnail is defenetly less then 200KB)