package databag import ( "time" "bytes" "errors" "net/http" "encoding/base64" ) func GetProfileImage(w http.ResponseWriter, r *http.Request) { var data []byte account, code, err := ParamAppToken(r, true); if err != nil { ErrResponse(w, code, err) return } if account.AccountDetail.Image == "" { ErrResponse(w, http.StatusNotFound, errors.New("profile image not set")) return } data, err = base64.StdEncoding.DecodeString(account.AccountDetail.Image) if err != nil { ErrResponse(w, http.StatusNotFound, errors.New("profile image not valid")) return } // response with content http.ServeContent(w, r, "image", time.Unix(account.Updated, 0), bytes.NewReader(data)) }