-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrom_file.go
58 lines (46 loc) · 1.11 KB
/
from_file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"bytes"
"io"
"mime/multipart"
"net/http"
log "github.com/sirupsen/logrus"
)
func resizeFromFileHandler(w http.ResponseWriter, req *http.Request) {
log.Trace("Hit resize from FILE")
if err := req.ParseMultipartForm(50 * MB); nil != err {
log.Error("while parse", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
defer func() {
err := req.MultipartForm.RemoveAll()
if err != nil {
log.Error("Cant delete multipart error", err)
}
}()
for _, fheaders := range req.MultipartForm.File {
for _, hdr := range fheaders {
log.Tracef("Income file len: %d", hdr.Size)
var (
err error
infile multipart.File
outbuffer bytes.Buffer
)
if infile, err = hdr.Open(); err != nil {
log.Errorf("Handle open error: %v", err)
w.WriteHeader(http.StatusInternalServerError)
continue
}
defer infile.Close()
_, err = io.Copy(&outbuffer, infile)
if err != nil {
log.Errorf("Create Read Input error %v", err)
w.WriteHeader(http.StatusInternalServerError)
continue
}
processBuffer(w, req, &outbuffer)
return
}
}
}