Commit f5a686c8 authored by duanjinfei's avatar duanjinfei

update return file content

parent 58e85a8b
...@@ -3,6 +3,7 @@ package controllers ...@@ -3,6 +3,7 @@ package controllers
import ( import (
"bytes" "bytes"
"crypto/ecdsa" "crypto/ecdsa"
"encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/astaxie/beego" "github.com/astaxie/beego"
...@@ -13,8 +14,9 @@ import ( ...@@ -13,8 +14,9 @@ import (
_ "image/gif" // 导入 GIF 支持 _ "image/gif" // 导入 GIF 支持
_ "image/jpeg" // 导入 JPEG 支持 _ "image/jpeg" // 导入 JPEG 支持
_ "image/png" // 导入 PNG 支持 _ "image/png" // 导入 PNG 支持
"io/ioutil"
"net/http" "net/http"
"os" "strings"
"time" "time"
"token-uri/models" "token-uri/models"
) )
...@@ -55,23 +57,18 @@ func (c *LLMController) GetContainerSign() { ...@@ -55,23 +57,18 @@ func (c *LLMController) GetContainerSign() {
func (c *LLMController) GetImage() { func (c *LLMController) GetImage() {
filePath := "response.png" // 替换为实际图片文件路径 filePath := "response.png" // 替换为实际图片文件路径
// 打开图片文件 // 打开图片文件
file, err := os.Open(filePath) readFile, err := ioutil.ReadFile(filePath)
if err != nil { if err != nil {
log.Error("Error opening file:", err) log.Error("Error opening file:", err)
c.ResponseInfo(500, "Error opening file:", err) c.ResponseInfo(500, "Error opening file:", err)
return return
} }
defer func(file *os.File) {
err := file.Close()
if err != nil {
log.Error("Error closing file:", err)
}
}(file)
// 设置 Content-Type 为图片类型 // 设置 Content-Type 为图片类型
c.Ctx.Output.Header("Content-Type", "image/jpeg") c.Ctx.Output.Header("Content-Type", "application/json")
toString := base64.StdEncoding.EncodeToString(readFile)
http.ServeContent(c.Ctx.ResponseWriter, c.Ctx.Request, "", time.Now(), file) res := fmt.Sprintf("data:image/png;base64,%s", toString)
http.ServeContent(c.Ctx.ResponseWriter, c.Ctx.Request, "", time.Now(), strings.NewReader(res))
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment