Skip to content

How can I save attachments #174

Jun 20, 2022 · 3 comments · 6 replies
Discussion options

You must be logged in to vote

Here is the code to save image/audio/video/documents received at WhatsApp:

		case evt.Message.ImageMessage != nil:
			img := evt.Message.GetImageMessage()
			if img != nil {
				data, err := global.Cli.Download(img)
				if err != nil {
					log.Printf("Failed to download image: %v", err)
					return
				}
				exts, _ := mime.ExtensionsByType(img.GetMimetype())
				path := fmt.Sprintf("./Downloads/Image/%s-%s%s", sender, evt.Info.ID, exts[0])
				err = os.WriteFile(path, data, 0600)
				if err != nil {
					log.Printf("Failed to save image: %v", err)
					return
				}
				log.Printf("Saved image in message to %s", path)
			}

		case evt.Message.AudioMessage != nil:
			audio := evt.Message.G…

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by hajsf
Comment options

You must be logged in to vote
3 replies
@mamur-rezeki
Comment options

@MeinDeutschkurs
Comment options

@MeinDeutschkurs
Comment options

Comment options

You must be logged in to vote
3 replies
@MeinDeutschkurs
Comment options

@mamur-rezeki
Comment options

@MeinDeutschkurs
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants