蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

56 lines
1.5 KiB

  1. package qiniu
  2. import (
  3. "time"
  4. "github.com/qiniu/api.v7/v7/auth/qbox"
  5. _ "github.com/qiniu/api.v7/v7/conf"
  6. "github.com/qiniu/api.v7/v7/storage"
  7. "applet/app/md"
  8. "applet/app/utils"
  9. )
  10. // 请求图片上传地址信息
  11. func ReqImgUpload(f *md.FileCallback, callbackUrl string) interface{} {
  12. if ext := utils.FileExt(f.FileName); ext == "png" || ext == "jpg" || ext == "jpeg" || ext == "gif" || ext == "bmp" || ext == "webp" {
  13. f.Width = "$(imageInfo.width)"
  14. f.Height = "$(imageInfo.height)"
  15. }
  16. f.Provider = "qiniu"
  17. f.FileSize = "$(fsize)"
  18. f.Hash = "$(etag)"
  19. f.Bucket = "$(bucket)"
  20. f.Mime = "$(mimeType)"
  21. f.Time = utils.Int64ToStr(time.Now().Unix())
  22. f.Sign = Sign(f.Time)
  23. putPolicy := storage.PutPolicy{
  24. Scope: BUCKET + ":" + f.FileName, // 使用覆盖方式时候必须请求里面有key,否则报错
  25. Expires: Expires,
  26. ForceSaveKey: true,
  27. SaveKey: f.FileName,
  28. MimeLimit: "image/*", // 只允许上传图片
  29. CallbackURL: callbackUrl,
  30. CallbackBody: utils.SerializeStr(f),
  31. CallbackBodyType: "application/json",
  32. }
  33. return &struct {
  34. Method string `json:"method"`
  35. Key string `json:"key"`
  36. Host string `json:"host"`
  37. Token string `json:"token"`
  38. }{Key: f.FileName, Method: "POST", Host: BUCKET_SCHEME + "://" + BUCKET_REGION, Token: putPolicy.UploadToken(qbox.NewMac(AK, SK))}
  39. }
  40. /*
  41. form表单上传
  42. 地址 : http://upload-z2.qiniup.com
  43. header
  44. - Content-Type : multipart/form-data
  45. body :
  46. - key : 文件名
  47. - token : 生成token
  48. - file : 待上传文件
  49. */