作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
这里是我的代码和输出:
func RestClient(req *http.Request) {
fmt.Println("main (120):::", req.MultipartForm.File)
}
main (120)::: &{map[userName:[0xc4200a66e0] diamond:[0xc4200f67b0] ]}
for k,v := range req.MultipartForm.File{
if k == "userName" {
for _, v2 := range v {
fmt.Println("main (130):::",v2)
}
}
}
> main (130)::: &{ map[Content-Length:[8]
> Content-Disposition:[form-data; name="dk"]
> Content-Transfer-Encoding:[binary] Content-Type:[multipart/form-data;
> charset=utf-8]] 8 [117 115 101 114 78 97 109 101] }
我想要 (slice byte [117 115 101 114 78 97 109 101]) 但无法提取,如何打印 (content []byte),正如我们从 FileHeader 结构中知道的字段:
type FileHeader struct {
Filename string
Header textproto.MIMEHeader
Size int64
content []byte
tmpfile string
}
提前致谢。
最佳答案
调用FileHeader.Open ,它返回一个 multipart.File :
type File interface {
io.Reader
io.ReaderAt
io.Seeker
io.Closer
}
你如何处理这个文件取决于你想对内容做什么。 ioutil.ReadAll 是一个选项,但通常将其保留原样并使用 io.Copy 将内容写入另一个 io.Writer 会更方便。阅读完后不要忘记调用 Close。
关于go - 如何在 golang 中从客户端接收 multipart?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49667405/
我是一名优秀的程序员,十分优秀!