互动
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.

41 lines
1.0 KiB

5 years ago
4 years ago
5 years ago
  1. package common
  2. import (
  3. "context"
  4. "fmt"
  5. "git.ouxuan.net/tommy/osmanthuswine/src/helper"
  6. "hudongzhuanjia/controllers"
  7. "net/http"
  8. "net/url"
  9. "path"
  10. "time"
  11. "github.com/tencentyun/cos-go-sdk-v5"
  12. )
  13. const upload_base_path = "html/annex"
  14. type AnnexCtl struct {
  15. controllers.AuthorCtl
  16. }
  17. //上传
  18. func (t *AnnexCtl) Upload() {
  19. //计算文件得md5
  20. uploadFile, err := t.Request.FILE.Open()
  21. u, _ := url.Parse("https://hudongzhuanjia-1251209212.cos.ap-guangzhou.myqcloud.com")
  22. b := &cos.BaseURL{BucketURL: u}
  23. client := cos.NewClient(b, &http.Client{
  24. Transport: &cos.AuthorizationTransport{
  25. SecretID: "AKIDo2B9WqpvkSKQPPpplVAdv65QdpDfMRIz",
  26. SecretKey: "fEcu35xdCbpU3azFLH2lU2f8UpAOQHZs",
  27. },
  28. })
  29. picName := fmt.Sprintf("hdzj/upload/%d%s%s", time.Now().UnixNano(), helper.CreateUUID(), path.Ext(t.Request.FILE.Filename))
  30. _, err = client.Object.Put(context.Background(), picName, uploadFile, nil)
  31. t.CheckErrDisplayByError(err)
  32. t.DisplayByData(map[string]interface{}{
  33. "url": fmt.Sprintf("%s/%s", u.String(), picName),
  34. })
  35. }