package lib // 存储相关功能的引入包只有这两个,后面不再赘述 // 存储相关功能的引入包只有这两个,后面不再赘述 import ( "Yunlot/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: conf.Qiniu_Dir + "/" + Tokey + "." + T_suffix, FsizeLimit: 1024 * 1024 * 10, // 10M //MimeLimit: "image/*", } upToken := putPolicy.UploadToken(Qiniu) return upToken }