|
@@ -2,8 +2,10 @@ package controllers
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"errors"
|
|
"errors"
|
|
|
|
|
+ "fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm"
|
|
|
|
|
+ "io"
|
|
|
"os"
|
|
"os"
|
|
|
"path"
|
|
"path"
|
|
|
"speechAnalysis/constvar"
|
|
"speechAnalysis/constvar"
|
|
@@ -268,10 +270,27 @@ func (slf AudioCtl) AudioDownload(c *gin.Context) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- c.Header("Content-Description", "File Transfer")
|
|
|
|
|
- c.Header("Content-Disposition", "attachment; filename="+audio.Name)
|
|
|
|
|
- c.Header("Content-Type", "application/octet-stream")
|
|
|
|
|
- c.File(audio.FilePath)
|
|
|
|
|
|
|
+ file, err := os.Open(audio.FilePath)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ util.ResponseFormat(c, code.InternalError, "文件打开失败")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ defer file.Close()
|
|
|
|
|
+
|
|
|
|
|
+ fileInfo, err := file.Stat()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ util.ResponseFormat(c, code.InternalError, "获取文件信息失败")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ c.Header("Content-Disposition", "inline; filename="+audio.Name) // 在浏览器中直接打开
|
|
|
|
|
+ c.Header("Content-Length", fmt.Sprint(fileInfo.Size()))
|
|
|
|
|
+ c.Header("Content-Type", "audio/mpeg") // 设置音频文件类型
|
|
|
|
|
+
|
|
|
|
|
+ if _, err := io.Copy(c.Writer, file); err != nil {
|
|
|
|
|
+ util.ResponseFormat(c, code.InternalError, "文件传输失败")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// BatchProcess
|
|
// BatchProcess
|