package controllers import ( "ERP_user/conf" beego "github.com/beego/beego/v2/server/web" "github.com/qiniu/go-sdk/v7/auth/qbox" "github.com/qiniu/go-sdk/v7/storage" uuid "github.com/satori/go.uuid" "gogs.baozhida.cn/zoie/ERP_libs/lib" "strconv" "time" ) type UpFileController struct { beego.Controller } // 列表 - func (c *UpFileController) UpFileToken() { var Qiniu *qbox.Mac Qiniu = qbox.NewMac(conf.Qiniu_AccessKey, conf.Qiniu_SecretKey) T_suffix := c.GetString("T_suffix") Tokey := strconv.FormatInt(time.Now().Unix(), 10) + uuid.NewV4().String() if len(T_suffix) == 0 { T_suffix = "png" } putPolicy := storage.PutPolicy{ Scope: conf.Qiniu_BUCKET, InsertOnly: 1, //仅能以新增模式上传文件。 Expires: 7200, //示例2小时有效期 ReturnBody: `{"key":"` + conf.OssQiniu + `/$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)"}`, ForceSaveKey: true, SaveKey: "UpImage/" + Tokey + "." + T_suffix, MimeLimit: "image/*;application/pdf;application/octet-stream", } upToken := putPolicy.UploadToken(Qiniu) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: upToken} c.ServeJSON() return }