yinbangzhong
2024-06-18 500985cf7556808ee42e2e9e3066bb4648a8e534
controllers/audio.go
@@ -7,6 +7,7 @@
   "gorm.io/gorm"
   "io"
   "mime/multipart"
   "net/url"
   "os"
   "path"
   "path/filepath"
@@ -28,14 +29,16 @@
// Upload
// @Tags      音频
// @Summary   上传音频
// @Accept     multipart/form-data
// @Produce   application/json
// @Param files formData []file false "多文件上传"
// @Param file formData []file false "多文件上传"
// @Success   200 {object} util.Response "成功"
// @Router    /api-sa/v1/audio/upload [post]
func (slf AudioCtl) Upload(c *gin.Context) {
   var headers []*multipart.FileHeader
   if len(c.Request.MultipartForm.File["file"]) > 1 {
      headers = c.Request.MultipartForm.File["file"]
   files, _ := c.MultipartForm()
   if len(files.File["file"]) > 1 {
      headers = files.File["file"]
   } else {
      util.ResponseFormat(c, code.RequestParamError, "文件需要一一对应")
      return
@@ -89,7 +92,7 @@
         //解析 交路号:123_公里标:321
         fileds := string(bts)
         arr = strings.Split(fileds, "_")
         if len(arr) > 1 {
         if len(arr) != 2 {
            util.ResponseFormat(c, code.RequestParamError, "文件内容格式不对")
            return
         } else {
@@ -291,8 +294,9 @@
   }
   if params.Filetype == 2 {
      filepath = audio.TxtFilePath
      //设置Content-Type为txt文件类型
      c.Header("Content-Type", "text/plain")
      //设置Content-Type为txt文件类型,避免中文乱码
      c.Header("Content-Type", "text/plain; charset=utf-8")
      c.Header("Content-Transfer-Encoding", "binary")
   }
   if filepath == "" {
      util.ResponseFormat(c, code.InternalError, "查询失败")
@@ -312,7 +316,7 @@
      return
   }
   c.Header("Content-Disposition", "inline; filename="+audio.Name) // 在浏览器中直接打开
   c.Header("Content-Disposition", "inline; filename="+url.PathEscape(audio.Name)) // 在浏览器中直接打开
   c.Header("Content-Length", fmt.Sprint(fileInfo.Size()))
   if _, err := io.Copy(c.Writer, file); err != nil {