From 4e60bfcf056bbbdab5d75fcfc406b6c7c07e1bff Mon Sep 17 00:00:00 2001 From: Heinrich 'Henrik' Langos Date: Sun, 22 Jan 2023 03:34:03 +0100 Subject: Fix upload error for large files This should avoid allocation of max_upload_size bytes of RAM. Instead we only allocate 1MB of RAM for the upload form decoder. - Fixes #67 --- app/app.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/app.go') diff --git a/app/app.go b/app/app.go index 1b1afe5..90af733 100644 --- a/app/app.go +++ b/app/app.go @@ -42,6 +42,9 @@ type App struct { Router *mux.Router } +// 1MB buffer in RAM seems enough +const uploadParserBuffer = 1_048_576 + // NewApp returns a new instance of App from Config. func NewApp(cfg *Config) (*App, error) { if cfg == nil { @@ -234,7 +237,7 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) { } a.render("upload", w, ctx) } else if r.Method == "POST" { - r.ParseMultipartForm(a.Config.Server.MaxUploadSize) + r.ParseMultipartForm(uploadParserBuffer) file, handler, err := r.FormFile("video_file") if err != nil { -- cgit v1.2.3