forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd_api_upload.go
42 lines (36 loc) · 927 Bytes
/
d_api_upload.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
package uadmin
import (
"net/http"
)
func dAPIUpload(w http.ResponseWriter, r *http.Request, schema *ModelSchema) (map[string]string, error) {
fileList := map[string]string{}
if r.MultipartForm == nil {
return fileList, nil
}
for k := range r.MultipartForm.File {
// Process File
// Check if the file is type file or image
var field *F
for i := range schema.Fields {
if schema.Fields[i].ColumnName == k[1:] {
field = &schema.Fields[i]
r.MultipartForm.File[k[1:]] = r.MultipartForm.File[k]
break
}
}
if field == nil {
Trail(WARNING, "dAPIUpload received a file that has no field: %s", k)
continue
}
s := r.Context().Value(CKey("session"))
var session *Session
if s != nil {
session = s.(*Session)
}
fileName := processUpload(r, field, schema.ModelName, session, schema)
if fileName != "" {
fileList[field.ColumnName] = fileName
}
}
return fileList, nil
}