面包店
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

req_img_upload.go 1.5 KiB

hace 9 meses
hace 8 meses
hace 9 meses
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package qiniu
  2. import (
  3. "applet/app/md"
  4. "applet/app/utils"
  5. "time"
  6. "github.com/qiniu/api.v7/v7/auth/qbox"
  7. _ "github.com/qiniu/api.v7/v7/conf"
  8. "github.com/qiniu/api.v7/v7/storage"
  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. */