Created
April 14, 2022 10:05
-
-
Save ric-v/862f1be3079d3ad78c6dca0a9370c9fb to your computer and use it in GitHub Desktop.
decode and save PNG to file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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