package controller import ( "eta_gn/eta_obs/controller/resp" "eta_gn/eta_obs/services/oss" "github.com/gin-gonic/gin" ) type ObsController struct{} // File // @Description 文件读取 // @Success 200 {string} string "获取成功" // @Router /auth/auth_code [post] func (a *ObsController) File(c *gin.Context) { objPath := c.Request.URL.Path // ico过滤 if objPath == `/favicon.ico` { return } ossClient := new(oss.MinioOss) fileBytes, contentType, err := ossClient.GetFile(objPath) if err != nil { resp.FailData("异常请求", objPath, c) return } //fileName := objPath[strings.LastIndex(objPath, "/")+1:] //contentDisposition := `attachment` //if strings.HasPrefix(contentType, "image/") { // contentDisposition = `inline` //} //c.Header("Content-Disposition", fmt.Sprintf("%s; filename=%s", contentDisposition, fileName)) c.Header("Content-Type", contentType) c.Writer.Write(fileBytes) return }