oss.go 748 B

1234567891011121314151617181920212223242526272829303132
  1. package services
  2. import (
  3. "errors"
  4. "github.com/aliyun/aliyun-oss-go-sdk/oss"
  5. "time"
  6. "eta_gn/eta_task/utils"
  7. )
  8. // UploadAudioAliyun 音频上传到阿里云
  9. func UploadAudioAliyun(filename, filepath string) (string, error) {
  10. if utils.AccessKeyId == `` {
  11. return "0", errors.New("阿里云信息未配置")
  12. }
  13. client, err := oss.New(utils.Endpoint, utils.AccessKeyId, utils.AccessKeySecret)
  14. if err != nil {
  15. return "1", err
  16. }
  17. bucket, err := client.Bucket(utils.Bucketname)
  18. if err != nil {
  19. return "2", err
  20. }
  21. path := utils.Upload_Audio_Dir + time.Now().Format("200601/20060102/")
  22. path += filename
  23. err = bucket.PutObjectFromFile(path, filepath)
  24. if err != nil {
  25. return "3", err
  26. }
  27. path = utils.Imghost + path
  28. return path, err
  29. }