-
-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image message unable to preview #204
Comments
Maybe you need to upload Thumbnail like you upload the image (but with Media thumbnail option) and attaching the response properties to the thumbnail fields. |
tried with whatsmeow.MediaLinkThumbnail, no luck, I found out that it maybe the reason of unsaved contact, but it sometime works on manually sending |
could you try out my image file? because I tried resize my image and my code is not working as yours, I use the same image bytes for image and its thumbnail, what am I doing it wrong? size: 12KB, W: 300, H: 245Update 1: I also tried different bytes for actual image 1MB with 12KB thumbnail upload, and also do both 245 x 245 pixels, maybe my code is incorrect? Update 2: Could it be the URL? seems like encrypted data I check the DirectPath and URL of the image, how can we be sure that image is upload successfully? but once clicked download button on there the image is viewable, so the upload should be completed?
|
JpegThumbnail is meant to be very small, 72x72 px at most. |
yes with 72x72 px, the preview is able to view now,
|
Worked for me, thumbnail configuration: // open "test.jpg"
file, err := os.Open("test.jpg")
if err != nil {
fmt.Println(err)
}
// decode jpeg into image.Image
img, err := jpeg.Decode(file)
if err != nil {
fmt.Println(err)
}
file.Close()
// resize to width 72 using Lanczos resampling
// and preserve aspect ratio
m := resize.Thumbnail(72, 72, img, resize.Lanczos3)
out, err := os.Create("test_resized.jpg")
if err != nil {
fmt.Println(err)
}
defer out.Close()
// write new image to file
jpeg.Encode(out, m, nil)
thumbnailBytes, err := os.ReadFile("test_resized.jpg")
if err != nil {
log.Errorf("Failed to read %s: %v", thumbnailPath, err)
return
} Video configuration: recipient, ok := parseJID("120363172773092731@g.us")
if !ok {
return
}
data, err := os.ReadFile("test-video.mp4")
if err != nil {
log.Errorf("Failed to read %s: %v", arquivoPath, err)
return
}
uploaded, err := cli.Upload(context.Background(), data, whatsmeow.MediaVideo)
if err != nil {
log.Errorf("Failed to upload file: %v", err)
return
}
msg := &waProto.Message{VideoMessage: &waProto.VideoMessage{
Url: proto.String(uploaded.URL),
DirectPath: proto.String(uploaded.DirectPath),
MediaKey: uploaded.MediaKey,
Mimetype: proto.String(http.DetectContentType(data)),
FileEncSha256: uploaded.FileEncSHA256,
FileSha256: uploaded.FileSHA256,
FileLength: proto.Uint64(uint64(len(data))),
Caption: proto.String("test caption"),
JpegThumbnail: thumbnailBytes,
}}
resp, err := cli.SendMessage(context.Background(), recipient, msg)
if err != nil {
log.Errorf("Error sending video message: %v", err)
} else {
log.Infof("Video message sent (server timestamp: %s)", resp.Timestamp)
} Configure the resize library:
import (
"github.com/nfnt/resize"
) |
I followed the documentation and perform a simple image upload but the image (bottom message) sent was unable to preview like we sending the image manually (top message)
NOTE: the receiver has no saved contact of the sender
my code to reproduce the issue:
The text was updated successfully, but these errors were encountered: