File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 4
4
"fmt"
5
5
"net/url"
6
6
"os"
7
+ "path"
7
8
"path/filepath"
8
9
"strings"
9
10
@@ -53,13 +54,26 @@ func (am *AvatarMiddleware) AvatarThumb() gin.HandlerFunc {
53
54
ctx .Next ()
54
55
return
55
56
}
57
+ ext := strings .ToLower (path .Ext (filePath )[1 :])
58
+ ctx .Header ("content-type" , fmt .Sprintf ("image/%s" , ext ))
56
59
_ , err = ctx .Writer .WriteString (string (avatarfile ))
57
60
if err != nil {
58
61
log .Error (err )
59
62
}
60
63
ctx .Abort ()
61
64
return
62
65
66
+ } else {
67
+ uUrl , err := url .Parse (u )
68
+ if err != nil {
69
+ ctx .Next ()
70
+ return
71
+ }
72
+ _ , urlfileName := filepath .Split (uUrl .Path )
73
+ uploadPath := am .serviceConfig .UploadPath
74
+ filePath := fmt .Sprintf ("%s/%s" , uploadPath , urlfileName )
75
+ ext := strings .ToLower (path .Ext (filePath )[1 :])
76
+ ctx .Header ("content-type" , fmt .Sprintf ("image/%s" , ext ))
63
77
}
64
78
ctx .Next ()
65
79
}
You can’t perform that action at this time.
0 commit comments