obs.go 931 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package controller
  2. import (
  3. "eta_gn/eta_obs/controller/resp"
  4. "eta_gn/eta_obs/services/oss"
  5. "github.com/gin-gonic/gin"
  6. )
  7. type ObsController struct{}
  8. // File
  9. // @Description 文件读取
  10. // @Success 200 {string} string "获取成功"
  11. // @Router /auth/auth_code [post]
  12. func (a *ObsController) File(c *gin.Context) {
  13. objPath := c.Request.URL.Path
  14. // ico过滤
  15. if objPath == `/favicon.ico` {
  16. return
  17. }
  18. ossClient := new(oss.MinioOss)
  19. fileBytes, contentType, err := ossClient.GetFile(objPath)
  20. if err != nil {
  21. resp.FailData("异常请求", objPath, c)
  22. return
  23. }
  24. //fileName := objPath[strings.LastIndex(objPath, "/")+1:]
  25. //contentDisposition := `attachment`
  26. //if strings.HasPrefix(contentType, "image/") {
  27. // contentDisposition = `inline`
  28. //}
  29. //c.Header("Content-Disposition", fmt.Sprintf("%s; filename=%s", contentDisposition, fileName))
  30. c.Header("Content-Type", contentType)
  31. c.Writer.Write(fileBytes)
  32. return
  33. }