@@ -15,7 +15,7 @@ import (
1515)
1616
1717const (
18- Version = "0.4 "
18+ Version = "0.5 "
1919)
2020
2121func init () {
@@ -27,6 +27,7 @@ func init() {
2727// uploaded file to a file on the disk.
2828type Upload struct {
2929 DestDir string `json:"dest_dir,omitempty"`
30+ FileFieldName string `json:"file_field_name,omitempty"`
3031 MaxFilesize int64 `json:"max_filesize,omitempty"`
3132 MaxFormBuffer int64 `json:"max_form_buffer,omitempty"`
3233 ResponseTemplate string `json:"response_template,omitempty"`
@@ -71,6 +72,13 @@ func (u *Upload) Provision(ctx caddy.Context) error {
7172 return mdall_err
7273 }
7374
75+ if u .FileFieldName == "" {
76+ u .logger .Warn ("Provision" ,
77+ zap .String ("msg" , "no FileFieldName specified (file_field_name), using the default one 'myFile'" ),
78+ )
79+ u .FileFieldName = "myFile"
80+ }
81+
7482 if u .ResponseTemplate == "" {
7583 u .logger .Warn ("Provision" ,
7684 zap .String ("msg" , "no ResponseTemplate specified (response_template), using the default one" ),
@@ -133,10 +141,10 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
133141 return caddyhttp .Error (http .StatusRequestEntityTooLarge , max_size_err )
134142 }
135143
136- // FormFile returns the first file for the given key `myFile`
144+ // FormFile returns the first file for the given file field key
137145 // it also returns the FileHeader so we can get the Filename,
138146 // the Header and the size of the file
139- file , handler , ff_err := r .FormFile ("myFile" )
147+ file , handler , ff_err := r .FormFile (u . FileFieldName )
140148 if ff_err != nil {
141149 u .logger .Error ("FormFile Error" ,
142150 zap .String ("requuid" , requuid ),
@@ -216,6 +224,10 @@ func (u *Upload) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
216224 if ! d .Args (& u .DestDir ) {
217225 return d .ArgErr ()
218226 }
227+ case "file_field_name" :
228+ if ! d .Args (& u .FileFieldName ) {
229+ return d .ArgErr ()
230+ }
219231 case "max_form_buffer" :
220232 var sizeStr string
221233 if ! d .AllArgs (& sizeStr ) {
0 commit comments