@@ -15,7 +15,7 @@ import (
1515)
1616
1717const (
18- Version = "0.3 "
18+ Version = "0.4 "
1919)
2020
2121func init () {
@@ -28,6 +28,7 @@ func init() {
2828type Upload struct {
2929 DestDir string `json:"dest_dir,omitempty"`
3030 MaxFilesize int64 `json:"max_filesize,omitempty"`
31+ MaxFormBuffer int64 `json:"max_form_buffer,omitempty"`
3132 ResponseTemplate string `json:"response_template,omitempty"`
3233 NotifyURL string `json:"notify_url,omitempty"`
3334 NotifyMethod string `json:"notify_method,omitempty"`
@@ -81,9 +82,14 @@ func (u *Upload) Provision(ctx caddy.Context) error {
8182 u .NotifyMethod = "GET"
8283 }
8384
85+ if u .MaxFormBuffer == 0 {
86+ u .MaxFormBuffer = 1000000000
87+ }
88+
8489 u .logger .Info ("Current Config" ,
8590 zap .String ("dest_dir" , u .DestDir ),
8691 zap .Int64 ("max_filesize" , u .MaxFilesize ),
92+ zap .Int64 ("max_form_buffer" , u .MaxFormBuffer ),
8793 zap .String ("response_template" , u .ResponseTemplate ),
8894 zap .String ("notify_method" , u .NotifyMethod ),
8995 zap .String ("notify_url" , u .NotifyURL ),
@@ -116,7 +122,7 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
116122 repl .Set ("http.upload.max_filesize" , u .MaxFilesize )
117123
118124 r .Body = http .MaxBytesReader (w , r .Body , u .MaxFilesize )
119- if max_size_err := r .ParseMultipartForm (u .MaxFilesize ); max_size_err != nil {
125+ if max_size_err := r .ParseMultipartForm (u .MaxFormBuffer ); max_size_err != nil {
120126 u .logger .Error ("ServeHTTP" ,
121127 zap .String ("requuid" , requuid ),
122128 zap .String ("message" , "The uploaded file is too big. Please choose an file that's less than MaxFilesize." ),
@@ -209,6 +215,16 @@ func (u *Upload) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
209215 if ! d .Args (& u .DestDir ) {
210216 return d .ArgErr ()
211217 }
218+ case "max_form_buffer" :
219+ var sizeStr string
220+ if ! d .AllArgs (& sizeStr ) {
221+ return d .ArgErr ()
222+ }
223+ size , err := humanize .ParseBytes (sizeStr )
224+ if err != nil {
225+ return d .Errf ("parsing max_size: %v" , err )
226+ }
227+ u .MaxFormBuffer = int64 (size )
212228 case "max_filesize" :
213229 var sizeStr string
214230 if ! d .AllArgs (& sizeStr ) {
0 commit comments