Fix upload error for large files (#71)
This should avoid allocation of max_upload_size bytes of RAM. Instead we only allocate 1MB of RAM for the upload form decoder. - Closes #67 Reviewed-on: https://git.mills.io/prologic/tube/pulls/71 Co-authored-by: Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io> Co-committed-by: Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io>
This commit is contained in:
parent
7e6e2a0c1c
commit
e14f19abd3
1 changed files with 4 additions and 1 deletions
|
@ -42,6 +42,9 @@ type App struct {
|
||||||
Router *mux.Router
|
Router *mux.Router
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1MB buffer in RAM seems enough
|
||||||
|
const uploadParserBuffer = 1_048_576
|
||||||
|
|
||||||
// NewApp returns a new instance of App from Config.
|
// NewApp returns a new instance of App from Config.
|
||||||
func NewApp(cfg *Config) (*App, error) {
|
func NewApp(cfg *Config) (*App, error) {
|
||||||
if cfg == nil {
|
if cfg == nil {
|
||||||
|
@ -234,7 +237,7 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
a.render("upload", w, ctx)
|
a.render("upload", w, ctx)
|
||||||
} else if r.Method == "POST" {
|
} else if r.Method == "POST" {
|
||||||
r.ParseMultipartForm(a.Config.Server.MaxUploadSize)
|
r.ParseMultipartForm(uploadParserBuffer)
|
||||||
|
|
||||||
file, handler, err := r.FormFile("video_file")
|
file, handler, err := r.FormFile("video_file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue