upload.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package controllers
  2. import (
  3. "Medical_ERP/conf"
  4. "github.com/qiniu/go-sdk/v7/auth/qbox"
  5. "github.com/qiniu/go-sdk/v7/storage"
  6. uuid "github.com/satori/go.uuid"
  7. "strconv"
  8. "time"
  9. )
  10. type UpFileController struct {
  11. BaseController
  12. }
  13. // 列表 -
  14. func (c *UpFileController) ConfigUpFileToken() {
  15. var Qiniu *qbox.Mac
  16. Qiniu = qbox.NewMac(conf.Qiniu_AccessKey, conf.Qiniu_SecretKey)
  17. T_suffix := c.GetString("T_suffix")
  18. Tokey := strconv.FormatInt(time.Now().Unix(), 10) + uuid.NewV4().String()
  19. if len(T_suffix) == 0 {
  20. T_suffix = "png"
  21. }
  22. putPolicy := storage.PutPolicy{
  23. Scope: conf.Qiniu_BUCKET,
  24. InsertOnly: 1, // 仅能以新增模式上传文件。
  25. Expires: 7200, //示例2小时有效期
  26. ReturnBody: `{"key":"` + conf.Qiniu_Url + `/$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)"}`,
  27. ForceSaveKey: true,
  28. SaveKey: "UpImage/" + Tokey + "." + T_suffix,
  29. FsizeLimit: 1024 * 1024 * 100,
  30. MimeLimit: "image/*;application/pdf;application/octet-stream;application/zip;application/x-tar",
  31. }
  32. upToken := putPolicy.UploadToken(Qiniu)
  33. c.OK(upToken, "")
  34. return
  35. }