Qiniu.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package lib
  2. //
  3. //// 存储相关功能的引入包只有这两个,后面不再赘述
  4. //import (
  5. // "context"
  6. // "github.com/qiniu/go-sdk/v7/auth/qbox"
  7. // "github.com/qiniu/go-sdk/v7/storage"
  8. // uuid "github.com/satori/go.uuid"
  9. // "strconv"
  10. // "time"
  11. //)
  12. //
  13. //var Qiniu *qbox.Mac
  14. //
  15. //// var (
  16. ////
  17. //// //BUCKET是你在存储空间的名称
  18. //// accessKey = "-8ezB_d-8-eUFTMvhOGbGzgeQRPeKQnaQ3DBcUxo"
  19. //// secretKey = "KFhkYxTAJ2ZPN3ZS3euTsfWk8-C92rKgkhAMkDRN"
  20. //// BUCKET = "bzdcoldoss"
  21. ////
  22. //// )
  23. //func init() {
  24. // Qiniu = qbox.NewMac(conf.Qiniu_AccessKey, conf.Qiniu_SecretKey)
  25. //}
  26. //
  27. //// if !lib.Pload_qiniu("ofile/"+timeStr+".xlsx","ofile/"+timeStr+".xlsx"){
  28. //// c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
  29. //// c.ServeJSON()
  30. //// return
  31. //// }
  32. //func Pload_qiniu(localFile string, name string) bool {
  33. // //localFile := "C:\\Users\\Administrator\\Downloads\\kodo-browser-Windows-x64-v1.0.15.zip"
  34. // //key := "kodo-browser-Windows-x64-v1.0.15.zip"
  35. // // 自定义返回值结构体
  36. // type MyPutRet struct {
  37. // Key string
  38. // Hash string
  39. // Fsize int
  40. // Bucket string
  41. // Name string
  42. // }
  43. //
  44. // //key := "your file save key"
  45. // // 使用 returnBody 自定义回复格式
  46. // putPolicy := storage.PutPolicy{
  47. // Scope: conf.Qiniu_BUCKET,
  48. // ReturnBody: `{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}`,
  49. // }
  50. //
  51. // upToken := putPolicy.UploadToken(Qiniu)
  52. // cfg := storage.Config{}
  53. // formUploader := storage.NewFormUploader(&cfg)
  54. // ret := MyPutRet{}
  55. // putExtra := storage.PutExtra{
  56. // Params: map[string]string{
  57. // "x:name": "github logo",
  58. // },
  59. // }
  60. // err := formUploader.PutFile(context.Background(), &ret, upToken, name, localFile, &putExtra)
  61. // if err != nil {
  62. // logs.Error("Pload_qiniu", err)
  63. // return false
  64. // }
  65. // logs.Println("七牛云", ret.Bucket, ret.Key, ret.Fsize, ret.Hash, ret.Name)
  66. // return true
  67. //}
  68. //
  69. //func UploadToken(T_suffix string) string {
  70. // Tokey := strconv.FormatInt(time.Now().Unix(), 10) + uuid.NewV4().String()
  71. // if len(T_suffix) == 0 {
  72. // T_suffix = ".png"
  73. // }
  74. // putPolicy := storage.PutPolicy{
  75. // Scope: conf.Qiniu_BUCKET,
  76. // InsertOnly: 1, // 仅能以新增模式上传文件。
  77. // Expires: 7200, //示例2小时有效期
  78. // ReturnBody: `{"key":"` + conf.OssQiniu + `/$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)"}`,
  79. // //{"key":"github-x.png","hash":"FqKXVdTvIx_mPjOYdjDyUSy_H1jr","fsize":6091,"bucket":"if-pbl","name":"github logo"}
  80. // //{"key":"` + conf.Oss + `/$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}
  81. // ForceSaveKey: true,
  82. // SaveKey: "UpImage/" + Tokey + "." + T_suffix,
  83. // //FsizeLimit: 1024 * 1024 * 1,
  84. // MimeLimit: "image/*;application/pdf;application/octet-stream",
  85. // }
  86. //
  87. // upToken := putPolicy.UploadToken(Qiniu)
  88. // return upToken
  89. //}