Support username arg in UploadResource().

This commit is contained in:
Gucheng Wang 2021-11-20 15:35:33 +08:00
parent 2b6f397bb9
commit 91c0282040

View File

@ -111,6 +111,11 @@ func (c *ApiController) UploadResource() {
}
defer file.Close()
if username == "" || fullFilePath == "" {
c.ResponseError(fmt.Sprintf("username or fullFilePath is empty: username = %s, fullFilePath = %s", username, fullFilePath))
return
}
filename := filepath.Base(fullFilePath)
fileBuffer := bytes.NewBuffer(nil)
if _, err = io.Copy(fileBuffer, file); err != nil {
@ -161,8 +166,11 @@ func (c *ApiController) UploadResource() {
switch tag {
case "avatar":
if user == nil {
c.ResponseError("user is nil for tag: \"avatar\"")
return
user = object.GetUser(username)
if user == nil {
c.ResponseError("user is nil for tag: \"avatar\"")
return
}
}
user.Avatar = fileUrl