webhook: resulting file was deleted because of defer outside of goroutine

This commit is contained in:
Julien Neuhart
2018-12-13 18:15:28 +01:00
parent 404535c512
commit 4c1699df6c
6 changed files with 41 additions and 30 deletions

View File

@@ -49,17 +49,17 @@ func newResource(c echo.Context) (*resource, error) {
r := &resource{values: v, dirPath: dirPath}
form, err := c.MultipartForm()
if err != nil {
return nil, fmt.Errorf("getting multipart form: %v", err)
return r, fmt.Errorf("getting multipart form: %v", err)
}
for _, files := range form.File {
for _, fh := range files {
in, err := fh.Open()
if err != nil {
return nil, fmt.Errorf("%s: opening file: %v", fh.Filename, err)
return r, fmt.Errorf("%s: opening file: %v", fh.Filename, err)
}
defer in.Close()
if err := r.writeFile(fh.Filename, in); err != nil {
return nil, err
return r, err
}
}
}