oss.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2019 autocareai.com. All rights reserved.
  2. // Use of this source code is governed by autocareai.com.
  3. package record
  4. import (
  5. "github.com/aliyun/aliyun-oss-go-sdk/oss"
  6. "m7s.live/engine/v4"
  7. //"fmt"
  8. "strings"
  9. )
  10. func OssGetUrl() string {
  11. endpoint := strings.Replace(engine.EngineConfig.OssConfig.Endpoint, "https://", "", -1)
  12. return "https://" + engine.EngineConfig.OssConfig.Bucket + "." + endpoint
  13. //return "https://dip-dev-test.oss-cn-shanghai.aliyuncs.com"
  14. }
  15. // UploadOss 上传本地文件到oss
  16. func UploadOss(source, file string) (string, error) {
  17. //engine.EngineConfig.OssConfig.Endpoint
  18. //fmt.Println("oss config1111111111111111111---------------------:",engine.EngineConfig.OssConfig.Bucket,engine.EngineConfig.OssConfig.Endpoint, engine.EngineConfig.OssConfig.AccessKeyId, engine.EngineConfig.OssConfig.AccessKeySecret)
  19. client, err := oss.New(engine.EngineConfig.OssConfig.Endpoint, engine.EngineConfig.OssConfig.AccessKeyId, engine.EngineConfig.OssConfig.AccessKeySecret)
  20. //client, err := oss.New("oss-cn-shanghai.aliyuncs.com", "LTAI5tMXuRXxUbNuD69ryfUh", "Pujpylo7AJ57pUCJR0NJR6HROLhVYb")
  21. if err != nil {
  22. return "", err
  23. }
  24. bucket, err := client.Bucket(engine.EngineConfig.OssConfig.Bucket)
  25. //bucket, err := client.Bucket("dip-dev-test")
  26. if err != nil {
  27. return "", err
  28. }
  29. err = bucket.PutObjectFromFile(file, source)
  30. if err != nil {
  31. return "", err
  32. }
  33. filePath := OssGetUrl() + "/" + file
  34. //fmt.Println("oss file------------------------- :",filePath)
  35. return filePath, nil
  36. }