You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MessagesSendMultiMedia returns rpc error code 400: MEDIA_INVALID when sending multiple media in a single post #1527
I am trying to send multiple media files (e.g., images) in a single post using MessagesSendMultiMedia, but I keep getting the error:
rpc error code 400: MEDIA_INVALID
before using MessagesSendMultiMedia you should upload all files to telegram, please check docs before creating a issue https://core.telegram.org/methods
@borzovplus I checked this and studied the documentation, but I still face the same problem. Have you tried using multiMedia yourself, if you know, can you please show me?
I can not to show, because I have a lot of abstractions (to much codes).
Try use "github.com/gotd/td/telegram/uploader" to upload Media before call MessagesSendMultiMedia, than create []tg.InputSingleMedia with uploaded medias
To make it work you should:
Step 1: Upload all media by calling MessagesUploadMedia() and use InputMediaUploadedPhoto type as media.
Step 2: Parse responses to build InputMediaPhoto type for every media
Step 3: Finally call MessagesSendMultiMedia and use InputMediaPhoto as a media type from step 2.
Looks like this, removed some error handling from the code.
For messages.sendMultiMedia, Telegram does not accept raw inputMediaUploaded* constructors directly in multi_media. The official docs now state this explicitly:
The medias to send: note that they must be separately uploaded using messages.uploadMedia first, using raw inputMediaUploaded* constructors is not supported.
Internally, message.UploadedPhoto(...).applyMulti calls messages.uploadMedia, converts the returned MessageMediaPhoto into InputMediaPhoto, and then Album sends it through messages.sendMultiMedia.
If using the raw generated API, the flow should look like this:
Activity
asadbekGo commentedon Mar 11, 2025
@ernado
borzovplus commentedon Mar 11, 2025
before using MessagesSendMultiMedia you should upload all files to telegram, please check docs before creating a issue https://core.telegram.org/methods
asadbekGo commentedon Mar 11, 2025
@borzovplus I checked this and studied the documentation, but I still face the same problem. Have you tried using multiMedia yourself, if you know, can you please show me?
borzovplus commentedon Mar 11, 2025
I can not to show, because I have a lot of abstractions (to much codes).
Try use "github.com/gotd/td/telegram/uploader" to upload Media before call MessagesSendMultiMedia, than create []tg.InputSingleMedia with uploaded medias
asadbekGo commentedon Mar 12, 2025
func UploadFile(ctx context.Context, client *telegram.Client, filePath string) (tg.InputFileClass, []byte, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, nil, fmt.Errorf("error opening file: %w", err)
}
defer file.Close()
}
@borzovplus Yes, I am using the same uploader package, but still no result.
shampigeon commentedon Mar 22, 2025
Have you found a solution? @asadbekGo
asadbekGo commentedon Mar 22, 2025
no, I still haven't found a solution. If you know a solution, please help @shampigeon
asadbekGo commentedon Apr 9, 2025
please help @ernado
meder111 commentedon May 19, 2025
Привет @asadbekGo нашел решение ?
asadbekGo commentedon Jul 2, 2025
@meder111 Привет, пока не нашел
fauxlevin commentedon May 2, 2026
To make it work you should:
Step 1: Upload all media by calling
MessagesUploadMedia()and useInputMediaUploadedPhototype as media.Step 2: Parse responses to build
InputMediaPhototype for every mediaStep 3: Finally call
MessagesSendMultiMediaand use InputMediaPhoto as a media type from step 2.Looks like this, removed some error handling from the code.
Figured it out from this comment: alik0211/mtproto-core#148 (comment)
expary commentedon Jun 8, 2026
For
messages.sendMultiMedia, Telegram does not accept rawinputMediaUploaded*constructors directly inmulti_media. The official docs now state this explicitly:Reference: https://core.telegram.org/method/messages.sendMultiMedia
So this will fail with
MEDIA_INVALID:The media has to be uploaded/associated first, then converted to an
InputMediaPhotoorInputMediaDocumentand passed tomessages.sendMultiMedia.If you use the higher-level
telegram/messagehelpers,gotdalready handles this flow for uploaded photos/documents in album mode:Internally,
message.UploadedPhoto(...).applyMulticallsmessages.uploadMedia, converts the returnedMessageMediaPhotointoInputMediaPhoto, and thenAlbumsends it throughmessages.sendMultiMedia.If using the raw generated API, the flow should look like this:
No
GroupedIDis needed onInputSingleMedia; Telegram groups the items because they are sent in onemessages.sendMultiMediacall.expary commentedon Jun 8, 2026
expary commentedon Jun 8, 2026
expary commentedon Jun 8, 2026
expary commentedon Jun 8, 2026