GolangNote

Golang笔记

golang 把上传文件转为byte

Permalink

golang 把上传文件转为byte

golang 把上传文件转为byte

Go: 把上传文件转为byte
1
2
3
4
5
6
7
8
9
10
11
12
file, header, err := ctx.Request.FormFile("file")    
defer file.Close()
if err != nil {
    return nil, err
}

buf := bytes.NewBuffer(nil)
if _, err := io.Copy(buf, file); err != nil {
    return nil, err
}

fmt.Println(buf.Bytes())

Related articles

Write a Comment to "golang 把上传文件转为byte"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.16.5 Processed in 1ms