improve (upload): Limit memory usage when parsing multipart form data, so that large files are stored in disk (#382)

Co-authored-by: Quentin Bramas <bramas@unistra.fr>
This commit is contained in:
Quentin Bramas 2021-05-25 13:57:46 +02:00 committed by GitHub
parent 4db1e9f216
commit bbe21185b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,15 +5,16 @@ import (
"encoding/base64"
"fmt"
"hash/fnv"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/model"
"io"
"net/http"
"os"
"path/filepath"
"strings"
"strconv"
"strings"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/model"
)
type FileInfo struct {
@ -301,6 +302,13 @@ func FileSave(ctx App, res http.ResponseWriter, req *http.Request) {
return
}
maxMemory := int64(32 << 20) // 32MB
err = req.ParseMultipartForm(maxMemory)
if err != nil {
SendErrorResult(res, err)
return
}
file, _, err := req.FormFile("file")
if err != nil {
SendErrorResult(res, err)