package tao_vegetable

import (
	"fmt"
	"git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability1475"
	"git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability1475/request"
)

// UploadImg 上传图片
func (a *API) UploadImg(param *request.AlibabaWdkPictureUploadRequest) (string, error) {
	client := ability1475.NewAbility1475(&a.client)

	data, err := client.AlibabaWdkPictureUpload(param, a.token)
	if err != nil {
		return "", err
	}
	if data.Result.ErrCode != nil {
		return "", fmt.Errorf(*data.Result.ErrMsg)
	}

	if data.Result.Model != nil {
		return *data.Result.Model.FullUrl, nil
	}

	return "", fmt.Errorf("图片上传返回异常")
}
