Reputation: 1383
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.
Upvotes: 1
Views: 1437
Reputation: 1383
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
for i:=0;i<len(fhs);i++{
f,err:=fhs[i].Open()
}
then i can do the next steps.
Upvotes: 1