How to Receive multipart from the client?

Okay, I took a look at Open()s code:

https://golang.org/src/mime/multipart/formdata.go?s=3582:3791#L140

func (fh *FileHeader) Open() (File, error) {
	if b := fh.content; b != nil {
		r := io.NewSectionReader(bytes.NewReader(b), 0, int64(len(b)))
		return sectionReadCloser{r}, nil
	}
	return os.Open(fh.tmpfile)
}

So as you can see, if there is a non nil content, you can read it from the returned File after Open()ing the FileHeader, you can’t know from your code though, if there was something in FileHeader.content or if you get a file from disk, as this information is abstracted away.

Remember: identifiers starting with lowercase letters are not exported from a package and therefore can’t be used from the “outside”

2 Likes