Sample code for 30+ languages & platforms
Go

Get Contents of File as Base64

See more Encryption Examples

Demonstrates how to read the contents of a file and convert to a base64 string.

Chilkat Go Downloads

Go
    success := false

    bd := chilkat.NewBinData()

    success = bd.LoadFile("qa_data/jpg/starfish.jpg")
    if success == false {
        fmt.Println("Failed to load file.")
        bd.DisposeBinData()
        return
    }

    fmt.Println(*bd.GetEncoded("base64"))

    // If you want mult-line base64:
    fmt.Println("--")
    fmt.Println(*bd.GetEncoded("base64_mime"))

    // If you want hex..
    fmt.Println("--")
    fmt.Println(*bd.GetEncoded("hex"))

    // etc.

    bd.DisposeBinData()