Black screen instead image
Checklist
- [x] I am reporting an issue in existing functionality that does not work as intended
- [x] I've searched for existing GitHub issues
Description
When I try to view an image that was sent as a file, a black screen is displayed
Expected Behavior
The image opens
Actual Behavior
Иlack screen is displayed
Steps to Reproduce
- Upload image as file by api
func prepareAttachments(attachments []Attachment, caption *string) ([]any, error) {
var prepared = make([]any, 0, len(attachments))
for i := range attachments {
attachment := tgbotapi.FileBytes{
Name: attachments[i].Name,
Bytes: attachments[i].Content,
}
fileSize := float64(len(attachments[i].Content) / 1024 / 1024)
if fileSize > maxFileSize {
attachments[i].Type = AttachmentDocument
}
if attachments[i].Type == AttachmentPhoto {
imageInfo, _, err := image.Decode(bytes.NewBuffer(attachments[i].Content))
if err != nil {
return nil, err
}
sumSizes := imageInfo.Bounds().Dx() + imageInfo.Bounds().Dy()
if sumSizes > maxSumOfSizesInPhoto {
attachments[i].Type = AttachmentDocument
}
}
if attachments[i].Type == AttachmentPhoto {
inputAttachment := tgbotapi.NewInputMediaPhoto(attachment)
inputAttachment.ParseMode = tgbotapi.ModeMarkdown
if caption != nil {
inputAttachment.Caption = *caption
}
prepared = append(prepared, inputAttachment)
continue
}
if attachments[i].Type == AttachmentDocument {
inputAttachment := tgbotapi.NewInputMediaDocument(attachment)
inputAttachment.ParseMode = tgbotapi.ModeMarkdown
if caption != nil {
inputAttachment.Caption = *caption
}
prepared = append(prepared, inputAttachment)
continue
}
return nil, fmt.Errorf("unknown attachment type %s", attachments[i].Type)
}
return prepared, nil
}
.....
preparedAttachments, err := prepareAttachments(attachments, text)
if err != nil {
return err
}
_, err = t.botClient.SendMediaGroup(tgbotapi.MediaGroupConfig{
ChatID: channelID,
Media: preparedAttachments,
})
- Open file in message (https://t.me/caressemoi/12627)
Screenshots and Videos
Latest logs from device:
Dec 5 02:03:40 Nikolays-iPad Telegram(UIKitCore)[480] <Notice>: Evaluating dispatch of UIEvent: 0x2826c6970; type: 0; subtype: 0; backing type: 11; shouldSend: 1; ignoreInteractionEvents: 0, systemGestureStateChange: 0
Dec 5 02:03:40 Nikolays-iPad Telegram(UIKitCore)[480] <Notice>: Sending UIEvent type: 0; subtype: 0; to windows: 1
Dec 5 02:03:40 Nikolays-iPad Telegram(UIKitCore)[480] <Notice>: Sending UIEvent type: 0; subtype: 0; to window: <_TtC7DisplayP33_83BFFE1175986BF91B85BE8424379B0412NativeWindow: 0x105818c00>; contextId: 0xDB987361
Dec 5 02:03:40 Nikolays-iPad Telegram(UIKitCore)[480] <Notice>: Evaluating dispatch of UIEvent: 0x2826c6970; type: 0; subtype: 0; backing type: 11; shouldSend: 1; ignoreInteractionEvents: 0, systemGestureStateChange: 0
Dec 5 02:03:40 Nikolays-iPad Telegram(UIKitCore)[480] <Notice>: Sending UIEvent type: 0; subtype: 0; to windows: 1
Dec 5 02:03:40 Nikolays-iPad Telegram(UIKitCore)[480] <Notice>: Sending UIEvent type: 0; subtype: 0; to window: <_TtC7DisplayP33_83BFFE1175986BF91B85BE8424379B0412NativeWindow: 0x105818c00>; contextId: 0xDB987361
Dec 5 02:03:40 Nikolays-iPad Telegram(UIKitCore)[480] <Notice>: Evaluating dispatch of UIEvent: 0x2826c6970; type: 0; subtype: 0; backing type: 11; shouldSend: 0; ignoreInteractionEvents: 0, systemGestureStateChange: 0
Dec 5 02:03:41 Nikolays-iPad Telegram(UIKitCore)[480] <Error>: Calling -viewWillAppear: directly on a view controller is not supported, and may result in out-of-order callbacks and other inconsistent behavior. Use the -beginAppearanceTransition:animated: and -endAppearanceTransition APIs on UIViewController to manually drive appearance callbacks instead. Make a symbolic breakpoint at UIViewControllerAlertForAppearanceCallbackMisuse to catch this in the debugger. View controller: <GalleryUI.GalleryController: 0x10fa00000>
Dec 5 02:03:41 Nikolays-iPad Telegram(UIKitCore)[480] <Error>: Calling -viewDidAppear: directly on a view controller is not supported, and may result in out-of-order callbacks and other inconsistent behavior. Use the -beginAppearanceTransition:animated: and -endAppearanceTransition APIs on UIViewController to manually drive appearance callbacks instead. Make a symbolic breakpoint at UIViewControllerAlertForAppearanceCallbackMisuse to catch this in the debugger. View controller: <GalleryUI.GalleryController: 0x10fa00000>
Dec 5 02:03:41 Nikolays-iPad Telegram(CoreMotion)[480] <Notice>: Stopping gesture updates
Dec 5 02:03:41 Nikolays-iPad Telegram(libxpc.dylib)[480] <Notice>: [0x10277cf30] invalidated on xpc_connection_cancel()
Dec 5 02:03:41 Nikolays-iPad Telegram(UIKitCore)[480] <Notice>: Evaluating dispatch of UIEvent: 0x2826c6970; type: 0; subtype: 0; backing type: 11; shouldSend: 0; ignoreInteractionEvents: 0, systemGestureStateChange: 1
https://github.com/TelegramMessenger/Telegram-iOS/assets/60335090/b4aba9e2-e0f3-43ed-866e-96af6cf1ed95
Environment
Device: Any IOS device
iOS version: 17.1.2
App version: 10.26.6
The same issue here. @ostiwe did you manage to fix it somehow?
The same issue here. @ostiwe did you manage to fix it somehow?
No
It looks like the problem is with the bot's API. What happens on the Bot API side:
1.1. When you use the sendDocument method and the file size is larger than 10 MB, Telegram does not process the file automatically - it does not create a thumbnail, nor does it add documentAttributeImageSize which is required for correct image display.
1.2. You can add a thumbnail manually because the Bot API allows you to pass a "thumbnail" argument to the sendDocument method, in which case the file you send will have the correct preview instead of the default file icon.
1.3. But even if you see the thumbnail, the document will not open correctly in the app and you will only see a black screen.
Even a locally hosted telegram-bot-api will not handle this properly.
The only solution I found for my needs was to skip the Bot Api layer and send the document directly through Mtproto, adding all the necessary metadata in the form of thumbnails and documentAttributeImageSize. In this case, even very large photos will open correctly.
I don't know, it seems like it has nothing to do with the iOS app, but the Bot Api should allow width and height to be passed directly to the sendDocument method, like sendVideo allows.