Skip to content

Commit

Permalink
remove any temporary files associated with a Form, fixes #347.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k1o committed Dec 26, 2023
1 parent a03b29b commit 792b1ac
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion server/internal/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ func New(conf *config.Server, webSocketHandler types.WebSocketHandler, desktop t
return
}

r.ParseMultipartForm(32 << 20)
err = r.ParseMultipartForm(32 << 20)
if err != nil || r.MultipartForm == nil {
logger.Warn().Err(err).Msg("failed to parse multipart form")
http.Error(w, "error parsing form", http.StatusBadRequest)
return
}

for _, formheader := range r.MultipartForm.File["files"] {
filePath := webSocketHandler.FileTransferPath(formheader.Filename)

Expand All @@ -187,6 +193,11 @@ func New(conf *config.Server, webSocketHandler types.WebSocketHandler, desktop t

io.Copy(f, formfile)
}

err = r.MultipartForm.RemoveAll()
if err != nil {
logger.Warn().Err(err).Msg("failed to remove multipart form")
}
})
}

Expand Down

0 comments on commit 792b1ac

Please sign in to comment.