fix save avatar

fixed save avatar `image not loaded  try to open it externally to fix format problem`
if response content length is 0, an error is reported.
This commit is contained in:
weibin 2021-12-25 17:13:13 +08:00
parent 1bdcfa296c
commit baab829493

View File

@ -75,6 +75,11 @@ func (u *User) SaveAvatar(filename string) error {
}
}
defer resp.Body.Close()
// 写文件前判断下 content length 是否是 0不然保存的头像会出现
// image not loaded try to open it externally to fix format problem 问题
if resp.ContentLength == 0 {
return fmt.Errorf("get avatar response content length is 0")
}
file, err := os.Create(filename)
if err != nil {
return err