Commit f5a686c8 authored by duanjinfei's avatar duanjinfei

update return file content

parent 58e85a8b
......@@ -3,6 +3,7 @@ package controllers
import (
"bytes"
"crypto/ecdsa"
"encoding/base64"
"encoding/json"
"fmt"
"github.com/astaxie/beego"
......@@ -13,8 +14,9 @@ import (
_ "image/gif" // 导入 GIF 支持
_ "image/jpeg" // 导入 JPEG 支持
_ "image/png" // 导入 PNG 支持
"io/ioutil"
"net/http"
"os"
"strings"
"time"
"token-uri/models"
)
......@@ -55,23 +57,18 @@ func (c *LLMController) GetContainerSign() {
func (c *LLMController) GetImage() {
filePath := "response.png" // 替换为实际图片文件路径
// 打开图片文件
file, err := os.Open(filePath)
readFile, err := ioutil.ReadFile(filePath)
if err != nil {
log.Error("Error opening file:", err)
c.ResponseInfo(500, "Error opening file:", err)
return
}
defer func(file *os.File) {
err := file.Close()
if err != nil {
log.Error("Error closing file:", err)
}
}(file)
// 设置 Content-Type 为图片类型
c.Ctx.Output.Header("Content-Type", "image/jpeg")
http.ServeContent(c.Ctx.ResponseWriter, c.Ctx.Request, "", time.Now(), file)
c.Ctx.Output.Header("Content-Type", "application/json")
toString := base64.StdEncoding.EncodeToString(readFile)
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