fix uploading file with wrong content. close #30

This commit is contained in:
vitalii 2019-01-03 20:38:58 +02:00
parent 6c32839dbd
commit 38f79aeaf1

View File

@ -211,8 +211,12 @@ func writeFile(path string, bytes []byte, mode os.FileMode) error {
} }
func getStream(pathOrString string) (io.ReadCloser, error) { func getStream(pathOrString string) (io.ReadCloser, error) {
fi, err := os.Stat(pathOrString) fi, err := os.Stat(pathOrString)
if err == nil { if err != nil {
return nil, err
}
if fi.IsDir() { if fi.IsDir() {
return nil, &os.PathError{ return nil, &os.PathError{
Op: "Open", Op: "Open",
@ -220,23 +224,15 @@ func getStream(pathOrString string) (io.ReadCloser, error) {
Err: errors.New("Path: '" + pathOrString + "' is a directory"), Err: errors.New("Path: '" + pathOrString + "' is a directory"),
} }
} }
f, err := os.Open(pathOrString) f, err := os.Open(pathOrString)
if err == nil { if err == nil {
return f, nil return f, nil
} }
return nil, &os.PathError{ return nil, &os.PathError{
Op: "Open", Op: "Open",
Path: pathOrString, Path: pathOrString,
Err: err, Err: err,
} }
} }
return nopCloser{strings.NewReader(pathOrString)}, nil
}
type nopCloser struct {
io.Reader
}
func (nopCloser) Close() error {
return nil
}