mirror of
https://github.com/mickael-kerjean/filestash
synced 2026-01-04 14:52:36 +01:00
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:
parent
4db1e9f216
commit
bbe21185b6
1 changed files with 11 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue