@@ -15,7 +15,7 @@ import (
15
15
)
16
16
17
17
const (
18
- Version = "0.3 "
18
+ Version = "0.4 "
19
19
)
20
20
21
21
func init () {
@@ -28,6 +28,7 @@ func init() {
28
28
type Upload struct {
29
29
DestDir string `json:"dest_dir,omitempty"`
30
30
MaxFilesize int64 `json:"max_filesize,omitempty"`
31
+ MaxFormBuffer int64 `json:"max_form_buffer,omitempty"`
31
32
ResponseTemplate string `json:"response_template,omitempty"`
32
33
NotifyURL string `json:"notify_url,omitempty"`
33
34
NotifyMethod string `json:"notify_method,omitempty"`
@@ -81,9 +82,14 @@ func (u *Upload) Provision(ctx caddy.Context) error {
81
82
u .NotifyMethod = "GET"
82
83
}
83
84
85
+ if u .MaxFormBuffer == 0 {
86
+ u .MaxFormBuffer = 1000000000
87
+ }
88
+
84
89
u .logger .Info ("Current Config" ,
85
90
zap .String ("dest_dir" , u .DestDir ),
86
91
zap .Int64 ("max_filesize" , u .MaxFilesize ),
92
+ zap .Int64 ("max_form_buffer" , u .MaxFormBuffer ),
87
93
zap .String ("response_template" , u .ResponseTemplate ),
88
94
zap .String ("notify_method" , u .NotifyMethod ),
89
95
zap .String ("notify_url" , u .NotifyURL ),
@@ -116,7 +122,7 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
116
122
repl .Set ("http.upload.max_filesize" , u .MaxFilesize )
117
123
118
124
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 {
120
126
u .logger .Error ("ServeHTTP" ,
121
127
zap .String ("requuid" , requuid ),
122
128
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 {
209
215
if ! d .Args (& u .DestDir ) {
210
216
return d .ArgErr ()
211
217
}
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 )
212
228
case "max_filesize" :
213
229
var sizeStr string
214
230
if ! d .AllArgs (& sizeStr ) {
0 commit comments