Do not use base64.StdEncoding.DecodeString, instead, configure the decoder directly fromr.Body
dec := base64.NewDecoder(base64.StdEncoding, r.Body)`
now use decfor example. dump to bytes.Bufferhow
buf := &bytes.Buffer{}
n, err := io.copy(buf, dec)
which will decode r.Bodyin buf or copy directly to http.Response or the file.
Or use the Peter method below if you keep everything in memory in order.