fix uploading file with wrong content. close #30
This commit is contained in:
parent
6c32839dbd
commit
38f79aeaf1
@ -211,32 +211,28 @@ 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 {
|
||||||
if fi.IsDir() {
|
return nil, err
|
||||||
return nil, &os.PathError{
|
}
|
||||||
Op: "Open",
|
|
||||||
Path: pathOrString,
|
if fi.IsDir() {
|
||||||
Err: errors.New("Path: '" + pathOrString + "' is a directory"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f, err := os.Open(pathOrString)
|
|
||||||
if err == nil {
|
|
||||||
return f, nil
|
|
||||||
}
|
|
||||||
return nil, &os.PathError{
|
return nil, &os.PathError{
|
||||||
Op: "Open",
|
Op: "Open",
|
||||||
Path: pathOrString,
|
Path: pathOrString,
|
||||||
Err: err,
|
Err: errors.New("Path: '" + pathOrString + "' is a directory"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nopCloser{strings.NewReader(pathOrString)}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type nopCloser struct {
|
f, err := os.Open(pathOrString)
|
||||||
io.Reader
|
if err == nil {
|
||||||
}
|
return f, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (nopCloser) Close() error {
|
return nil, &os.PathError{
|
||||||
return nil
|
Op: "Open",
|
||||||
|
Path: pathOrString,
|
||||||
|
Err: err,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user