@@ -2,7 +2,7 @@ package upload
2
2
3
3
import (
4
4
"fmt"
5
- "io/ioutil "
5
+ "io"
6
6
"net/http"
7
7
"os"
8
8
@@ -118,7 +118,7 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
118
118
r .Body = http .MaxBytesReader (w , r .Body , u .MaxFilesize )
119
119
if max_size_err := r .ParseMultipartForm (u .MaxFilesize ); max_size_err != nil {
120
120
u .logger .Error ("ServeHTTP" ,
121
- zap .String ("Request uuid " , requuid ),
121
+ zap .String ("requuid " , requuid ),
122
122
zap .String ("message" , "The uploaded file is too big. Please choose an file that's less than MaxFilesize." ),
123
123
zap .String ("MaxFilesize" , humanize .Bytes (uint64 (u .MaxFilesize ))),
124
124
zap .Error (max_size_err ),
@@ -132,7 +132,7 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
132
132
file , handler , ff_err := r .FormFile ("myFile" )
133
133
if ff_err != nil {
134
134
u .logger .Error ("FormFile Error" ,
135
- zap .String ("Request uuid " , requuid ),
135
+ zap .String ("requuid " , requuid ),
136
136
zap .String ("message" , "Error Retrieving the File" ),
137
137
zap .Error (ff_err ),
138
138
zap .Object ("request" , caddyhttp.LoggableHTTPRequest {Request : r }))
@@ -146,7 +146,7 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
146
146
147
147
if tmpf_err != nil {
148
148
u .logger .Error ("TempFile Error" ,
149
- zap .String ("Request uuid " , requuid ),
149
+ zap .String ("requuid " , requuid ),
150
150
zap .String ("message" , "Error at TempFile" ),
151
151
zap .Error (tmpf_err ),
152
152
zap .Object ("request" , caddyhttp.LoggableHTTPRequest {Request : r }))
@@ -156,22 +156,24 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
156
156
157
157
// read all of the contents of our uploaded file into a
158
158
// byte array
159
- fileBytes , io_err := ioutil .ReadAll (file )
159
+ //fileBytes, io_err := ioutil.ReadAll(file)
160
+ fileBytes , io_err := io .Copy (tempFile , file )
160
161
if io_err != nil {
161
- u .logger .Error ("ReadAll Error" ,
162
- zap .String ("Request uuid " , requuid ),
163
- zap .String ("message" , "Error at ReadAll " ),
162
+ u .logger .Error ("Copy Error" ,
163
+ zap .String ("requuid " , requuid ),
164
+ zap .String ("message" , "Error at io.Copy " ),
164
165
zap .Error (io_err ),
165
166
zap .Object ("request" , caddyhttp.LoggableHTTPRequest {Request : r }))
166
167
return caddyhttp .Error (http .StatusInternalServerError , io_err )
167
168
}
168
169
// write this byte array to our temporary file
169
- tempFile .Write (fileBytes )
170
+ // tempFile.Write(fileBytes)
170
171
171
172
u .logger .Info ("Successful Upload Info" ,
172
- zap .String ("Request uuid " , requuid ),
173
+ zap .String ("requuid " , requuid ),
173
174
zap .String ("Uploaded File" , handler .Filename ),
174
175
zap .Int64 ("File Size" , handler .Size ),
176
+ zap .Int64 ("written-bytes" , fileBytes ),
175
177
zap .Any ("MIME Header" , handler .Header ),
176
178
zap .Object ("request" , caddyhttp.LoggableHTTPRequest {Request : r }))
177
179
0 commit comments