move defer file.Close() to before validateContentType because that could cause problems

This commit is contained in:
grumbulon 2023-01-21 11:21:41 -05:00
parent 320f757917
commit 7e6594f3c7

View file

@ -65,13 +65,14 @@ func ReceiveFile(w http.ResponseWriter, r *http.Request) {
return
}
defer file.Close() //nolint: errcheck
ok := validateContentType(file)
if !ok {
http.Error(w, "file must be text/plain", http.StatusUnsupportedMediaType)
return
}
defer file.Close() //nolint: errcheck
name := strings.Split(header.Filename, ".")