fix: memory runtime nil

This commit is contained in:
minoplhy 2024-04-14 19:22:45 +07:00
parent b52d99c45f
commit fa8788bd29
Signed by: minoplhy
GPG Key ID: 41D406044E2434BF

View File

@ -54,16 +54,17 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
// The argument to FormFile must match the name attribute // The argument to FormFile must match the name attribute
// of the file input on the frontend // of the file input on the frontend
file, fileHeader, err := r.FormFile("file") file, fileHeader, err := r.FormFile("file")
if err != nil {
if err.Error() == "http: request body too large" { if err.Error() == "http: request body too large" {
http.Error(w, handler.ErrorResponseBuild(http.StatusRequestEntityTooLarge, "Request Body is too large!"), http.StatusRequestEntityTooLarge) http.Error(w, handler.ErrorResponseBuild(http.StatusRequestEntityTooLarge, "Request Body is too large!"), http.StatusRequestEntityTooLarge)
handler.ErrorLogBuilder([]string{r.RemoteAddr}, "Request Body is too large!") handler.ErrorLogBuilder([]string{r.RemoteAddr}, "Request Body is too large!")
return return
} } else {
if err != nil {
http.Error(w, handler.ErrorResponseBuild(http.StatusInternalServerError, "Something went wrong!"), http.StatusInternalServerError) http.Error(w, handler.ErrorResponseBuild(http.StatusInternalServerError, "Something went wrong!"), http.StatusInternalServerError)
handler.ErrorLogBuilder([]string{r.RemoteAddr}, err.Error()) handler.ErrorLogBuilder([]string{r.RemoteAddr}, err.Error())
return return
} }
}
defer file.Close() defer file.Close()
handler.InfoLogBuilder([]string{r.RemoteAddr}, "Received a successful POST") handler.InfoLogBuilder([]string{r.RemoteAddr}, "Received a successful POST")