Skip to content

Instantly share code, notes, and snippets.

@ric-v
Created April 14, 2022 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ric-v/862f1be3079d3ad78c6dca0a9370c9fb to your computer and use it in GitHub Desktop.
Save ric-v/862f1be3079d3ad78c6dca0a9370c9fb to your computer and use it in GitHub Desktop.
decode and save PNG to file
// decode the content and save to storage path location
func decodeAndSave(content, storagePath string, w http.ResponseWriter) {
// decode the payload content
data, err := base64.StdEncoding.DecodeString(string(content))
if err != nil {
fmt.Fprintf(w, "An error happened while decoding base64")
fmt.Println(err)
return
}
// store to stoage path
err = ioutil.WriteFile(storagePath, data, 0644)
if err != nil {
fmt.Fprintf(w, "An error happened while writing file")
fmt.Println(err)
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment