如何将* multipart.FileHeader中包含的文件的主体/内容读入GO中的一个字节([]字节)。
我唯一需要做的就是将内容读入一个巨大的字节片段,但当然我想要文件的确切大小。 我希望之后用md5散列文件内容。
// file is a *multipart.FileHeader gotten from http request.
fileContent, _ := file.Open()
var byteContainer []byte
byteContainer = make([]byte, 1000000)
fileContent.Read(byteContainer)
fmt.Println(byteContainer)
答案 0 :(得分:1)
https://play.golang.org/p/FUgPAZ9w2X
在你的情况下做;
byteContainer, err := ioutil.ReadAll(fileContent) // why the long names though?
fmt.Printf("size:%d", len(byteContainer))
您可能还希望从multipart
package docs看到此示例,
https://play.golang.org/p/084tWn65-d