package services import ( "errors" "github.com/aliyun/aliyun-oss-go-sdk/oss" "os" "time" "eta_gn/eta_report/utils" ) type AliOss struct{} func (m *AliOss) UploadFile(fileName, filePath, savePath string) (string, error) { defer func() { _ = os.Remove(filePath) }() if utils.AccessKeyId == `` { return "0", errors.New("阿里云信息未配置") } client, err := oss.New(utils.Endpoint, utils.AccessKeyId, utils.AccessKeySecret) if err != nil { return "1", err } bucket, err := client.Bucket(utils.Bucketname) if err != nil { return "2", err } path := savePath if savePath == "" { path = utils.UploadDir + time.Now().Format("200601/20060102/") + fileName } err = bucket.PutObjectFromFile(path, filePath) if err != nil { return "3", err } resourceUrl := utils.Imghost + path return resourceUrl, err } func (m *AliOss) GetUploadToken() (token OssToken, err error) { return }