From adfb9023c2fd00ec14ea753b49334bd5b9b00c57 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'app/app.go') diff --git a/app/app.go b/app/app.go index afcaa0f..617cb17 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 { @@ -235,9 +238,7 @@ func (a *App) uploadHandler(respWriter http.ResponseWriter, request *http.Reques a.renderUploadPage(respWriter) } else if request.Method == "POST" { - // The number here is probably used in the wrong place. - // Why should we expect tube to fit all uploads into memory? - request.ParseMultipartForm(a.Config.Server.MaxUploadSize) + request.ParseMultipartForm(uploadParserBuffer) // get information from the upload form and make sure it is valid videoTitleFromUpload := request.FormValue("video_title") -- cgit v1.2.3