Go-whatsapp: How to save media messages to physical files we can play?

Created on 11 Oct 2019  路  2Comments  路  Source: Rhymen/go-whatsapp

Hi friends! I need to save media messages to physical files I can play outside the projects. Example: Image, Audio, Video...

When I do: data, err := message.Download() I can't see a file with the final file...

PD: I know others languages but I'm novice in Go :(

Thanks!

Most helpful comment

if it's on linux, the downloaded file will be in / tmp

You need to move it, where you like (/tmp will be deleted if you restart your server)
as sample below, downloaded file will copy to directory "media/"
with filename same as original

        data, err := message.Download()
    filename := fmt.Sprintf("%v/%v.%v", "media", message.Info.Id, strings.Split(message.Type, "/")[1])
    file, err := os.Create(filename)
    defer file.Close()
        _, err = file.Write(data)

All 2 comments

if it's on linux, the downloaded file will be in / tmp

You need to move it, where you like (/tmp will be deleted if you restart your server)
as sample below, downloaded file will copy to directory "media/"
with filename same as original

        data, err := message.Download()
    filename := fmt.Sprintf("%v/%v.%v", "media", message.Info.Id, strings.Split(message.Type, "/")[1])
    file, err := os.Create(filename)
    defer file.Close()
        _, err = file.Write(data)

Pretty thanks @hrizal it worked perfect! :)

Was this page helpful?
0 / 5 - 0 ratings