345.jpeg

import (
    "context"
    "github.com/qiniu/go-sdk/v7/auth/qbox"
    "github.com/qiniu/go-sdk/v7/storage"
    "mime/multipart"
    "test.pkg/go-cms/common"
)

var AccessKey = "123344"
var SecretKey = "22222222222222222"
var Bucket = "erty"
var ImgUrl = "https://download.tt.tt/"


func UpLoadFile(file multipart.File, fileSize int64) (string, int) {
    putPolicy := storage.PutPolicy{
        Scope: Bucket,
    }
    mac := qbox.NewMac(AccessKey, SecretKey)
    upToken := putPolicy.UploadToken(mac)

    cfg := storage.Config{
        Zone:          &storage.ZoneHuadong,
        UseCdnDomains: false,
        UseHTTPS:      false,
    }

    putExtra := storage.PutExtra{}

    formUploader := storage.NewFormUploader(&cfg)
    ret := storage.PutRet{}

    err := formUploader.PutWithoutKey(context.Background(), &ret, upToken, file, fileSize, &putExtra)
    if err != nil {
        return "", common.ERROR
    }
    url := ImgUrl + ret.Key
    return url, common.SUCCSE

}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code