Go – 多个文件的formFile

huangapple go评论76阅读模式
英文:

Go - formFile for multiple files

问题

formFile函数工作得很好,但是在文档中说“FormFile返回提供的表单键的第一个文件”。有没有办法获取一个带有类似以下输入的HTML表单的多个文件:

<input type="file" name="myfiles" multiple="multiple">
英文:

The formFile function works perfectly but in the docs it´s said that the "FormFile returns the first file for the provided form key". Is there a way of obtaining the several files that an html form with an input like:

&lt;input type=&quot;file&quot; name=&quot;myfiles&quot; multiple=&quot;multiple&quot;&gt;

might return?

答案1

得分: 20

FormFile是一个方便的函数。您可以手动解析并找到在MultipartForm中寻找的文件。

req.ParseMultipartForm(32 << 20) // 32MB是FormFile使用的默认值
fhs := req.MultipartForm.File["myfiles"]
for _, fh := range fhs {
    f, err := fh.Open()
    // f是其中一个文件
}
英文:

FormFile is a convenience function. You can manually parse and find the files you are looking for in the MultipartForm.

req.ParseMultipartForm(32 &lt;&lt; 20) // 32MB is the default used by FormFile
fhs := req.MultipartForm.File[&quot;myfiles&quot;]
for _, fh := range fhs {
    f, err := fh.Open()
    // f is one of the files
}

huangapple
  • 本文由 发表于 2013年3月4日 21:15:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/15202448.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定