package lib // 存储相关功能的引入包只有这两个,后面不再赘述 // 存储相关功能的引入包只有这两个,后面不再赘述 import ( "AIOTCOER/conf" "github.com/qiniu/go-sdk/v7/auth/qbox" "github.com/qiniu/go-sdk/v7/storage" uuid "github.com/satori/go.uuid" "strconv" "time" ) var Qiniu *qbox.Mac func init() { Qiniu = qbox.NewMac(conf.Qiniu_AccessKey, conf.Qiniu_SecretKey) } func UploadToken(T_suffix string) string { 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)"}`, //{"key":"github-x.png","hash":"FqKXVdTvIx_mPjOYdjDyUSy_H1jr","fsize":6091,"bucket":"if-pbl","name":"github logo"} //{"key":"` + conf.Oss + `/$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"} ForceSaveKey: true, SaveKey: "UpOTA/" + Tokey + "." + T_suffix, //FsizeLimit: 1024 * 1024 * 1, //MimeLimit: "image/*;application/*;", } upToken := putPolicy.UploadToken(Qiniu) return upToken }