作者 yangfu

音频上传修改

1 package v1 1 package v1
2 2
3 import ( 3 import (
  4 + "bytes"
  5 + "fmt"
4 "opp/controllers" 6 "opp/controllers"
5 "opp/protocol" 7 "opp/protocol"
6 "opp/services/upload" 8 "opp/services/upload"
@@ -52,14 +54,17 @@ func (this *UploadController) Voice() { @@ -52,14 +54,17 @@ func (this *UploadController) Voice() {
52 var request = &protocol.FileRequest{} 54 var request = &protocol.FileRequest{}
53 if len(this.Ctx.Request.MultipartForm.File) != 0 { 55 if len(this.Ctx.Request.MultipartForm.File) != 0 {
54 var tmp *protocol.FileResponse 56 var tmp *protocol.FileResponse
55 - for _, v := range this.Ctx.Request.MultipartForm.File {  
56 - request.Files = v 57 + var logBuf = bytes.NewBufferString("")
  58 + for _, key := range upload.GetSortFileKeys(this.Ctx.Request.MultipartForm.File) {
  59 + request.Files = this.Ctx.Request.MultipartForm.File[key]
  60 + logBuf.WriteString(fmt.Sprintf(" key:%v 文件数量:%v ", key, len(request.Files)))
57 if tmp, err = upload.Voice(request); err != nil { 61 if tmp, err = upload.Voice(request); err != nil {
58 log.Error(err) 62 log.Error(err)
59 return 63 return
60 } 64 }
61 rsp.Paths = append(rsp.Paths, tmp.Paths...) 65 rsp.Paths = append(rsp.Paths, tmp.Paths...)
62 } 66 }
  67 + log.Debug("【上传音频文件】 ", logBuf.String())
63 } 68 }
64 msg = protocol.NewReturnResponse(rsp, err) 69 msg = protocol.NewReturnResponse(rsp, err)
65 } 70 }
@@ -80,7 +85,7 @@ func (this *UploadController) Video() { @@ -80,7 +85,7 @@ func (this *UploadController) Video() {
80 var tmp *protocol.FileResponse 85 var tmp *protocol.FileResponse
81 for _, v := range this.Ctx.Request.MultipartForm.File { 86 for _, v := range this.Ctx.Request.MultipartForm.File {
82 request.Files = v 87 request.Files = v
83 - if tmp, err = upload.Video(request); err != nil { 88 + if tmp, err = upload.Voice(request); err != nil {
84 log.Error(err) 89 log.Error(err)
85 return 90 return
86 } 91 }
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "os" 8 "os"
9 "path" 9 "path"
10 "path/filepath" 10 "path/filepath"
  11 + "sort"
11 "time" 12 "time"
12 13
13 "opp/protocol" 14 "opp/protocol"
@@ -123,3 +124,12 @@ func ResizeImage(fileType, sourcePath, prefix, subfix string, file *multipart.Fi @@ -123,3 +124,12 @@ func ResizeImage(fileType, sourcePath, prefix, subfix string, file *multipart.Fi
123 log.Debug(fmt.Sprintf("resize iamge:%v w:%v h:%v file:%v kb", filename, Rectangle.Dx(), Rectangle.Dy(), file.Size/1024)) 124 log.Debug(fmt.Sprintf("resize iamge:%v w:%v h:%v file:%v kb", filename, Rectangle.Dx(), Rectangle.Dy(), file.Size/1024))
124 return 125 return
125 } 126 }
  127 +
  128 +//获取排序键值
  129 +func GetSortFileKeys(files map[string][]*multipart.FileHeader) (keys []string) {
  130 + for k, _ := range files {
  131 + keys = append(keys, k)
  132 + }
  133 + sort.Strings(keys)
  134 + return
  135 +}