How can i get the file size from *multipart.FileHeader

971 views
Skip to first unread message

BOat Korachal

unread,
Aug 27, 2014, 5:44:29 PM8/27/14
to golan...@googlegroups.com

as the document said, after i call Open() it will return the File interface for access the file part

// File is an interface to access the file part of a multipart message.
// Its contents may be either stored in memory or on disk.
// If stored on disk, the File's underlying concrete type will be an *os.File.
type File interface {
io.Reader
io.ReaderAt
io.Seeker
io.Closer
}

So if the content stored on disk, I can use type assertion and call Stat() to get its size.
but the problem is if the content stored in memory, it will return an unexported struct 
sectionReadCloser

type sectionReadCloser struct {
*io.SectionReader
}

The io.SectionReader has the method Size(), but is there any way to call it?

Thank you, and sorry for my poor English :)

Tamás Gulácsi

unread,
Aug 28, 2014, 12:11:36 AM8/28/14
to golan...@googlegroups.com
Look at the Seeker interface: you can call Seek(0,2) which returns the length, then Seek(0,0).

BOat Korachal

unread,
Aug 28, 2014, 1:51:11 AM8/28/14
to golan...@googlegroups.com
Thanks !
Reply all
Reply to author
Forward
0 new messages