dongling0519 2014-02-27 12:10
浏览 45

如何用Go发布文件数组?

i have a form with many options to post, and post files with slice,but in Go, Request.ParseForm(),only get the first file, how should i resolve with file slice?

in html

<form enctype="multipart/form-data" method="POST" action="/homeworks" >
  {{if .success}}
    <p>flash success</p>
  {{end}}

  <div id="postform">
    本次作业标题
      <input type="text" name="title" />
      <br>
    <div class="postoption"> 
      添加项目
      <input type="text" name="option[]" />
      音频文件
      <input type="file" name="radio[]" />
      答案
      <input type="text" name="answer[]" />
    </div>
  </div>

  <input type="submit" value="提交" />
</form>

if i do like

    file,header,err:=r.FormFile("file")
    fmt.Println(header)
    if err!=nil{
        panic(err)
    }

it will panic no such file, how can i get files slice. if i change it to radio ,it works,but
can not get file slice.

  • 写回答

1条回答 默认 最新

  • duanji9378 2014-02-28 11:16
    关注

    that's finally how i deal with it, By reading Go source code of formfile()

    fhs := r.MultipartForm.File["radio"]
    

    fhs are the Headers of FileHeader of mutlipart .

    by useing Open method, i can get the interface [file][http://golang.org/pkg/mime/multipart/#File]

    for i:=0;i<len(fhs);i++{
        f,err:=fhs[i].Open()
    }
    

    then i can do the next steps.

    评论

报告相同问题?

悬赏问题

  • ¥15 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类