I am trying to convert a base64 encoding to a png image and ouput the image as response for a web request. Can I do this without creating a file in the server?
the 'ServeFile' of http works only when the image is saved as a file. but, I would like to decode the base64 string to image data and then directly write that to the output.
thanks.
Using base64.NewDecoder, for example :
func Handler(res http.ResponseWriter, req *http.Request) {
//in this example the client submits the base64 image, however
// you can use any io.Reader and pass it to NewDecoder.
dec := base64.NewDecoder(base64.StdEncoding, req.Body)
res.Header().Set("Content-Typee", "image/png")
io.Copy(res, dec)
}