Пример #1
0
func UpdateAvatar(w http.ResponseWriter, r *http.Request) {
	user := context.Get(r, "user").(store.User)
	url := fmt.Sprintf(store.UserAvatarURL, user.ID())

	finalURL, header, err := httputil.SaveFileWithExtension(w, r, "image", url)
	if err != nil || header == nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	if err = user.UpdateAvatarURL(finalURL); err != nil {
		response.ServerError(w, err)
		return
	}

	response.OK(w, nil)
}
Пример #2
0
func SaveProjectImage(w http.ResponseWriter, r *http.Request, projectID int64) (bool, error) {
	url := fmt.Sprintf(ProjectImageURL, projectID)

	finalURL, header, err := httputil.SaveFileWithExtension(w, r, "image", url)
	if err != nil || header == nil {
		if err := os.Chdir(".."); err != nil {
			debug.Error(err)
			return false, err
		}
		return false, nil
	}

	if err := updateProjectImage(projectID, finalURL); err != nil {
		debug.Error(err)
		return false, err
	}

	return true, nil
}