Skip to content

Commit

Permalink
update img header
Browse files Browse the repository at this point in the history
  • Loading branch information
aichy126 committed Feb 7, 2023
1 parent a8c2982 commit 860b1a3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/base/middleware/avatar.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/url"
"os"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -53,13 +54,26 @@ func (am *AvatarMiddleware) AvatarThumb() gin.HandlerFunc {
ctx.Next()
return
}
ext := strings.ToLower(path.Ext(filePath)[1:])
ctx.Header("content-type", fmt.Sprintf("image/%s", ext))
_, err = ctx.Writer.WriteString(string(avatarfile))
if err != nil {
log.Error(err)
}
ctx.Abort()
return

} else {
uUrl, err := url.Parse(u)
if err != nil {
ctx.Next()
return
}
_, urlfileName := filepath.Split(uUrl.Path)
uploadPath := am.serviceConfig.UploadPath
filePath := fmt.Sprintf("%s/%s", uploadPath, urlfileName)
ext := strings.ToLower(path.Ext(filePath)[1:])
ctx.Header("content-type", fmt.Sprintf("image/%s", ext))
}
ctx.Next()
}
Expand Down

0 comments on commit 860b1a3

Please sign in to comment.