Use a File interface to allow alternative source for file upload
smasher164 opened this issue · 1 comments
smasher164 commented
Currently in order to POST a multipart message, I create a temporary file and upload that. However, instead of requiring a file to be created on disk, there should be a mechanism to allow arbitrary data sources that implement a common interface. I propose https://golang.org/pkg/mime/multipart/#File.
type File interface {
io.Reader
io.ReaderAt
io.Seeker
io.Closer
}
This exposes enough information to construct the body buffer I use in the http library. This way, I can write a filestring
as follows:
type filestring struct {
*strings.Reader
}
func (fs *filestring) Close() error {
return nil
}
func NewFileString(s string) *filestring {
return &filestring{strings.NewReader(s)}
}
godovdm commented
@smasher164 Sorry for posting it here, but I can't find any information. Could you please teach me how to upload files using existing version of surf? Thanks in advance!