FindUploadedFiles extracts all form files of "key" from a http request and returns a slice with filesystem.File instances (if any).
(key string)
| 99 | // FindUploadedFiles extracts all form files of "key" from a http request |
| 100 | // and returns a slice with filesystem.File instances (if any). |
| 101 | func (e *Event) FindUploadedFiles(key string) ([]*filesystem.File, error) { |
| 102 | if e.Request.MultipartForm == nil { |
| 103 | err := e.Request.ParseMultipartForm(DefaultMaxMemory) |
| 104 | if err != nil { |
| 105 | return nil, err |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if e.Request.MultipartForm == nil || e.Request.MultipartForm.File == nil || len(e.Request.MultipartForm.File[key]) == 0 { |
| 110 | return nil, http.ErrMissingFile |
| 111 | } |
| 112 | |
| 113 | result := make([]*filesystem.File, 0, len(e.Request.MultipartForm.File[key])) |
| 114 | |
| 115 | for _, fh := range e.Request.MultipartForm.File[key] { |
| 116 | file, err := filesystem.NewFileFromMultipart(fh) |
| 117 | if err != nil { |
| 118 | return nil, err |
| 119 | } |
| 120 | |
| 121 | result = append(result, file) |
| 122 | } |
| 123 | |
| 124 | return result, nil |
| 125 | } |
| 126 | |
| 127 | // Store |
| 128 | // ------------------------------------------------------------------- |