package controllers import ( "Medical_ERP/conf" "github.com/qiniu/go-sdk/v7/auth/qbox" "github.com/qiniu/go-sdk/v7/storage" uuid "github.com/satori/go.uuid" "strconv" "time" ) type UpFileController struct { BaseController } // 列表 - func (c *UpFileController) ConfigUpFileToken() { 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.Qiniu_Url + `/$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)"}`, ForceSaveKey: true, SaveKey: "UpImage/" + Tokey + "." + T_suffix, FsizeLimit: 1024 * 1024 * 100, MimeLimit: "image/*;application/pdf;application/octet-stream;application/zip;application/x-tar", } upToken := putPolicy.UploadToken(Qiniu) c.OK(upToken, "") return }