Go decode base64 image.. the easy way

I was banging my head against this for hours and then I found the solution.

While attempting to Decode a jpg image from base64 I kept getting a missing SOI marker error.

And then I found out that it’s way easier to just use image.Decode (the generic version from the “image” package directly) which will basically decode anything you throw at it 🙂

base64Data := b64.NewDecoder(b64.StdEncoding, strings.NewReader(userData))
img, str, err := image.Decode(base64Data)
if err != nil {
    log.Println("Error decoding image: " + err.Error() + " str: " + str)

Maybe this can save somebody a little time.